Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Network Module

This module provides basic classes to implement network access in a portable way. More...

Classes

class  ClientSocket
 
class  Connection
 
class  Exception
 
class  ServerSocket
 
class  Server
 

Detailed Description

This module provides basic classes to implement network access in a portable way.

For a client, the basic class is the ClientSocket that opens a bidirectional TCP/IP connection to a remote socket. The input and output streams are provided using elm::io::InStream and elm::io::OutStream.

In the opposite, the ServerSocket provides basic facilities to build a server that opens a connection on a random or a selected port and listen for connection. A Connection is manages a socket and provides access using elm::io::InStream and elm::io::Outstream.

The Server wraps around a ServerSocket and implements a waiting loop for connection. When a connection is established, the protected function Server::onConnection() is called to let implement the behavior of the server application itself. Below is an example of echo server:

#include <elm/net/ServerSocket.h>
using namespace elm;
class EchoServer: public net::Server {
public:
EchoServer(void): Server(7) { }
protected:
virtual void onConnection(Connection& connection) {
while(true) {
int c = connection.in().read();
if(c < 0)
break;
connection.out().write(c);
}
}
};
elm
Definition: adapter.h:26
elm::net::Server
Definition: ServerSocket.h:48