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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

string S.get host( ) returns the host name.<br />

int S.get port( ) returns the port number.<br />

int S.get timeout( ) returns the timeout interval length in seconds.<br />

int S.get qlength( ) returns the queue length.<br />

string S.get ip( ) returns the ip address.<br />

bool S.connect(int sec = 10)<br />

tries to establish a connection from a client to a server.<br />

If the connection can be established within sec seconds,<br />

the operation returns true and false otherwise.<br />

bool S.listen( ) creates a socket endpoint on the server, performs address<br />

binding and signals readiness of a server to receive<br />

data.<br />

bool S.accept( ) the server takes a request from the queue.<br />

void S.disconnect( ) ends a connection.<br />

Sending and receiving packets<br />

void<br />

void<br />

void<br />

S.send file(string fname)<br />

sends the contents of file fname.<br />

S.send bytes(char ∗ buf , int numb)<br />

sends numb bytes starting at address buf .<br />

S.send string(string msg)<br />

sends string msg.<br />

void S.send int(int x) sends (a text representation of) integer x.<br />

bool<br />

char∗<br />

int<br />

S.receive file(string fname)<br />

S.receive bytes(int& numb)<br />

S.receive bytes(char ∗ buf , int buf sz)<br />

receives data and writes it to file fname.<br />

receives numb bytes. <strong>The</strong> function allocates memory<br />

and returns the first address of the allocated memory.<br />

numb is used as the return parameter for the number<br />

of received bytes.<br />

receives at most buf sz bytes and writes them into the<br />

buffer buf . It returns the number of bytes supplied by<br />

the sender (maybe more than buf sz), or -1 in case of<br />

an error.

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

Saved successfully!

Ooh no, something went wrong!