The Library

- Algorithms
- API Wrappers
- Bayesian Nets
- Compression
- Containers
- Graph Tools
- Image Processing
- Linear Algebra
- Machine Learning
- Metaprogramming
- Miscellaneous
- Networking
- Optimization
- Parsing

Help/Info

- Examples: C++
  - 3D_Point_Cloud
  - Assignment_Learning
  - Base64_Encoder
  - Bayesian_Network
  - Bayesian_Network_From_Disk
  - Bayesian_Network_GUI
  - Bridge
  - BSP
  - C-Support_Vector_Machine
  - Cmd_Line_Parser
  - Compress_Stream
  - Config_File_Reader
  - Custom_Trainers
  - Directory_Navigation
  - Empirical_Kernel_Map
  - Face_Detection
  - Face_Landmark_Detection
  - FHOG_Feature_Extraction
  - FHOG_Object_Detection
  - Graph_Labeling
  - GUI
  - Hough_Transform
  - HTTP_Server
  - Image
  - IO Socket Streams
  - IO Streams Server
  - Kernel_Centroid
  - Kernel_K-Means_Clustering
  - Kernel_Ridge_Regression
  - Kernel_RLS_Filtering
  - Kernel_RLS_Regression
  - KRR_Classification
  - Learning_to_Track
  - Linear_Assignment_Problems
  - Linear_Manifold_Regularizer
  - Logger
  - Logger_Advanced
  - Logger_Custom_Output
  - Matrix
  - Matrix_Expressions
  - Member_Function_Pointer
  - Model_Selection
  - Multiclass_Classification
  - Multithreaded_Object
  - Neural_Network
  - Non-Linear Least Squares
  - Nu-Support_Vector_Machine
  - Numerical_Integration
  - Object_Detector
  - Object_Detector_Advanced
  - One_Class_Classifiers
  - Online_SVM
  - Optimization
  - Parallel_For_Loops
  - Pipe
  - Pipe_2
  - Quantum_Computing
  - Queue
  - Rank_Features
  - Relevance_Vector_Classification
  - Relevance_Vector_Regression
  - Running_Stats
  - Sequence_Labeling
  - Sequence_Segmentation
  - Sockets
  - Sockstreambuf
  - Sparse_Vectors
  - SQLite
  - Std_C++_Allocator
  - Structural_Support_Vector_Machines
  - Support_Vector_Regression
  - SURF
  - SVM-Rank
  - Threaded_Object
  - Threads
  - Thread_Function
  - Thread_Pool
  - Timer
  - Train_Object_Detector
  - Train_Shape_Predictor
  - Using_Custom_Kernels
  - Video_Object_Tracking
  - Webcam_Face_Pose_Estimation
  - XML_Parser
- Examples: Python
  - Face_Detector
  - Face_Landmark_Detection
  - find_candidate_object_locations
  - Linear_Assignment_Problems
  - Sequence_Segmenter
  - Structural_Support_Vector_Machines
  - SVM-Rank
  - Train_Object_Detector
  - Train_Shape_Predictor
- FAQ
- Home
- How to compile
- How to contribute
- Index
- Introduction
- License
- Python API
- Suggested Books

Current Release

- Change Log
- Release Notes
- Version: 18.15

Last Modified: Dec 28, 2012

# 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

- bridge
- iosockstream
- linker
- server
- server_http
- server_iostream
- sockstreambuf

BSP

- bsp_connect
- bsp_context
- bsp_listen
- bsp_listen_dynamic_port

[top]

# bridge

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.

`#include <dlib/bridge.h>`
Detailed Documentation
C++ Example Programs: bridge_ex.cpp
[top]

# bsp_connect

This function spawns a BSP job consisting of a number of network hosts as well as the local host.
`#include <dlib/bsp.h>`
Detailed Documentation
C++ Example Programs: bsp_ex.cpp
[top]

# bsp_context

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.
`#include <dlib/bsp.h>`
Detailed Documentation
C++ Example Programs: bsp_ex.cpp
[top]

# bsp_listen

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.
`#include <dlib/bsp.h>`
Detailed Documentation
C++ Example Programs: bsp_ex.cpp
[top]

# bsp_listen_dynamic_port

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.
`#include <dlib/bsp.h>`
Detailed Documentation
[top]

# iosockstream

This is an iostream object that reads/writes from a TCP network connection.
`#include <dlib/iosockstream.h>`
Detailed Documentation
C++ Example Programs: iosockstream_ex.cpp
[top]

# linker

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.
`#include <dlib/linker.h>`
Detailed Documentation
[top]

# server

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.
`#include <dlib/server.h>`
Detailed Documentation
C++ Example Programs: sockets_ex.cpp
[top]

# server_http

This is an extension of the server_iostream object which turns it into a simple HTTP server.
`#include <dlib/server.h>`
Detailed Documentation
C++ Example Programs: server_http_ex.cpp
[top]

# server_iostream

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.
`#include <dlib/server.h>`
Detailed Documentation
C++ Example Programs: server_iostream_ex.cpp
[top]

# sockstreambuf

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.
`#include <dlib/sockstreambuf.h>`
Detailed Documentation
C++ Example Programs: sockstreambuf_ex.cpp