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.

4.14 Socket Streambuffer ( socket streambuf )<br />

1. Definition<br />

An instance sb of class socket streambuf can be used as an adapter: It turns a leda socket<br />

s into a C++-streambuf object. This object can be used in standard C++ ostreams and<br />

istreams to make the communication through the socket easier. A socket streambuf can<br />

also be applied within an encoding ostream or a decoding istream provided by <strong>LEDA</strong> to<br />

send compressed or encrypted data over a socket connection (see Sections 9.19 and 9.20).<br />

Observe that socket streambuf itself does not apply cryptography to secure the transmitted<br />

data. All data is sent as it is. If you want to secure your data, consider using the<br />

class secure socket streambuf (see Section 10.7).<br />

If two parties want to use the class socket streambuf to exchange data they have to do<br />

the following. First they establish a connection through leda sockets. <strong>The</strong>n each party<br />

contructs an instance of the class socket streambuf which is attached to its socket. This<br />

is shown in an example at the end of this manual page.<br />

Every instance sb has an out-buffer where outgoing data is buffered before it is sent<br />

through the socket over the internet. In addition it has an in-buffer to store data that<br />

has been received through the socket. <strong>The</strong> user may specify the maximum size of each<br />

buffer. <strong>The</strong> actual size of each buffer is determined in a negotiation between the server<br />

and the client at the beginning of the communication. <strong>The</strong> size of outgoing packets from<br />

the server is set to the minimum of the out-buffer size of the server and the in-buffer size<br />

of the client. <strong>The</strong> size of the incoming packets is determined in an analogous way.<br />

#include < <strong>LEDA</strong>/coding/socket streambuf.h ><br />

2. Creation<br />

socket streambuf<br />

sb(leda socket& s, uint32 out buf sz = DefaultBufferSize,<br />

uint32 in buf sz = DefaultBufferSize,<br />

bool send acknowledge = false);<br />

creates a sb and attaches it to the socket s. <strong>The</strong> parameters<br />

out buf sz and in buf sz determine the maximum size of the outbuffer<br />

and the in-buffer. send acknowledge specifies whether an<br />

acknowledgement is sent for every received packet.<br />

Precondition: <strong>The</strong> connection between the server and the client<br />

must have been established when sb is created.<br />

3. Operations<br />

<strong>The</strong> class socket streambuf inherits most of its operations from the class streambuf that<br />

belongs to the C++ standard library. Usually there is no need to call these operations<br />

explicitly. (You can find documentation for streambuf at http://www.cplusplus.com)

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

Saved successfully!

Ooh no, something went wrong!