31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4.13 Sockets ( leda socket )<br />

1. Definition<br />

A data packet consists of a sequence of bytes (in C of type unsigned char)<br />

c 0 , c 1 , c 2 , c 3 , x 1 , . . . , x n . <strong>The</strong> first four bytes encode the number n of the following bytes<br />

such that n = c 0 + c 1 · 2 8 + c 2 · 2 16 + c 3 · 2 24 . <strong>The</strong> <strong>LEDA</strong> data type leda socket offers,<br />

in addition to the operations for establishing a socket connection, functions for sending<br />

and receiving packets across such a connection. It is also possible to set a receive limit;<br />

if such a receive limit is set, messages longer than the limit will be refused. If the limit is<br />

negative (default), no messages will be refused.<br />

In particular, the following operations are available:<br />

#include < <strong>LEDA</strong>/system/socket.h ><br />

2. Creation<br />

leda socket S(const char ∗ host, int port);<br />

leda socket S(const char ∗ host);<br />

creates an instance S of type leda socket associated with host name<br />

host and port number port.<br />

creates an instance S of type leda socket associated with host name<br />

host.<br />

leda socket S;<br />

creates an instance S of type leda socket.<br />

3. Operations<br />

void<br />

S.set host(const char ∗ host)<br />

sets the host name to host.<br />

void S.set port(int port) sets the port number to port.<br />

int S.get limit( ) returns the receive limit parameter.<br />

void S.set limit(int limit) sets the receive limit parameter to limit. If a negative<br />

limit is set, the limit parameter will be ignored.<br />

void<br />

void<br />

void<br />

S.set qlength(int len) sets the queue length to len.<br />

S.set timeout(int sec)<br />

sets the timeout interval to sec seconds.<br />

S.set error handler(void (∗f)(leda socket& , string))<br />

sets the error handler to function f.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!