# Networking

This page documents tools built on top of the dlib sockets API. Therefore, all these tools are focused on providing some kind of higher level networking abstraction or service.

Objects
linker
server
server_iostream
server_http
bridge
sockstreambuf
iosockstream
BSP
bsp_connect
bsp_listen
bsp_listen_dynamic_port
bsp_context
linker
dlib/linker.h
dlib/linker/linker_kernel_abstract.h
This object represents something that takes two connections and lets them talk to each other. ie. any incoming data from one connection is passed unaltered to the other and vice versa.
bridge
dlib/bridge.h
dlib/bridge/bridge_abstract.h
This object is a tool for bridging a pipe object between two network connected applications.

The bridge object is designed to link two pipes together as efficiently as possible. To demonstrate its speed, I ran two experiments where a bridge was used to connect a desktop PC to a laptop, both running Ubuntu 12.04 and connected via gigabit ethernet. The first experiment is to test its bulk transfer speed while the second experiment measures how many separate objects the bridge can transfer each second.

In the first experiment, 1-megapixel images, represented with array<rgb_pixel> objects, were sent. The transfer rate was 112 megabytes/second, saturating the gigabit ethernet link. The second experiment used a pipe<char> and bridge to send individual char variables over the network. In this experiment, I was able to send 3.2 million objects a second (i.e. the receiving end was getting a char back from pipe::dequeue() 3.2 million times each second).

For reference, these experiments were carried out on a desktop with a 2.67GHz Intel Core-i7 CPU and a laptop with a 2.20GHz Intel Core-i7 CPU.

bridge_ex.cpp.html
bsp_connect
dlib/bsp.h
dlib/bsp/bsp_abstract.h
This function spawns a BSP job consisting of a number of network hosts as well as the local host.
bsp_ex.cpp.html
bsp_listen
dlib/bsp.h
dlib/bsp/bsp_abstract.h
This function listens for a TCP connection from the bsp_connect routine. Once this connection is established, a user supplied function will be executed and it will then be able to participate in a BSP computation as one of the processing nodes.
bsp_ex.cpp.html
bsp_listen_dynamic_port
dlib/bsp.h
dlib/bsp/bsp_abstract.h
This function listens for a TCP connection from the bsp_connect routine. Once this connection is established, a user supplied function will be executed and it will then be able to participate in a BSP computation as one of the processing nodes. This function has the additional ability to select the listening TCP port automatically from the set of available ports.
bsp_context
dlib/bsp.h
dlib/bsp/bsp_abstract.h
This is a tool used to implement algorithms using the Bulk Synchronous Parallel (BSP) computing model. In particular, this object defines the API used for communication between BSP jobs.
bsp_ex.cpp.html
server
dlib/server.h
dlib/server/server_kernel_abstract.h
This object represents a server that listens on a port and spawns new threads to handle each new connection. It also manages the connections and threads for you.
sockets_ex.cpp.html
server_iostream
dlib/server.h
dlib/server/server_iostream_abstract.h
This is an extension of the server object that redefines the on_connect() function so that instead of giving you a connection object you get an istream and ostream object.
server_iostream_ex.cpp.html
server_http
dlib/server.h
dlib/server/server_http_abstract.h
This is an extension of the server_iostream object which turns it into a simple HTTP server.
server_http_ex.cpp.html
iosockstream
dlib/iosockstream.h
dlib/iosockstream/iosockstream_abstract.h
This is an iostream object that reads/writes from a TCP network connection.
iosockstream_ex.cpp.html
sockstreambuf
dlib/sockstreambuf.h
dlib/sockstreambuf/sockstreambuf_abstract.h
This object represents a stream buffer for connection objects. If you are considering using this object then you should also take a look at the iosockstream.
sockstreambuf_ex.cpp.html