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.

ool sb.failed( ) returns whether a failure has occured.<br />

string sb.get error( ) returns an error message (if available).<br />

void sb.sputEOF( ) signals the end of the transmission to the receiving<br />

socket, so that it does not wait for further data. (This<br />

function is called automatically in the destructor unless<br />

it has been called explicitly by the user. If sb is not<br />

immediately destroyed after the end of the transmission<br />

then you should call sputEOF explicitly, otherwise<br />

the receiving party might incur a timeout error.)<br />

bool sb.has put EOF( ) returns whether EOF has already been sent.<br />

bool sb.has got EOF( ) returns whether EOF has already been received.<br />

leda socket& sb.get socket( )<br />

returns the socket to which sb is attached.<br />

uint32 sb.get outgoing packet size( )<br />

uint32 sb.get incoming packet size( )<br />

bool sb.waits for acknowledge( )<br />

bool sb.sends acknowledge( )<br />

4. Example<br />

returns the (actual) outgoing packet size.<br />

returns the (actual) incoming packet size.<br />

returns whether sb expects an acknowledgement for<br />

outgoing packets.<br />

returns whether sb sends an acknowledgement for incoming<br />

packets.<br />

<strong>The</strong> following example shows how the usage of sb from the server and from the client side.<br />

In our example the server sends a string, which is received by the client. (Note that it<br />

would also be possible that the client sends and the server receives data.)<br />

In order to add compression to the example simply replace “ostream” by<br />

“encoding ostream” and “istream” by “decoding istream” as indicated in<br />

the comments.<br />

void socket_example_server(int port)<br />

{<br />

leda_socket sock;<br />

sock.set_port(port);<br />

// open port

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

Saved successfully!

Ooh no, something went wrong!