Sha256: 3808e61ecc7de85d6ddca53d31cc26b4f79dbb2a95d0bd36e4a7ccb1aa3bfb32

Contents?: true

Size: 1.26 KB

Versions: 13

Compression:

Stored size: 1.26 KB

Contents

// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*

    This is an example illustrating the use of the sockets and
    server components from the dlib C++ Library.

    This is a simple echo server.  It listens on port 1234 for incoming
    connections and just echos back any data it receives.  

*/




#include <dlib/sockets.h>
#include <dlib/server.h>
#include <iostream>

using namespace dlib;
using namespace std;



class serv : public server
{
    void on_connect  (
        connection& con
    )
    {
        char ch;
        while (con.read(&ch,1) > 0)
        {
            // we are just reading one char at a time and writing it back
            // to the connection.  If there is some problem writing the char
            // then we quit the loop.  
            if (con.write(&ch,1) != 1)
                break;
        }
    }

};


int main()
{
    try
    {
        serv our_server;

        // set up the server object we have made
        our_server.set_listening_port(1234);
        // Tell the server to begin accepting connections.
        our_server.start_async();

        cout << "Press enter to end this program" << endl;
        cin.get();
    }
    catch (exception& e)
    {
        cout << e.what() << endl;
    }
}

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dlib-1.2.2 ext/dlib-19.4/examples/sockets_ex.cpp
dlib-1.2.1 ext/dlib-19.4/examples/sockets_ex.cpp
dlib-1.2.0 ext/dlib-19.4/examples/sockets_ex.cpp
dlib-1.1.5 ext/dlib-19.4/examples/sockets_ex.cpp
dlib-1.1.4 ext/dlib-19.4/examples/sockets_ex.cpp
dlib-1.1.3 ext/dlib-19.4/examples/sockets_ex.cpp
dlib-1.1.2 ext/dlib-19.4/examples/sockets_ex.cpp
dlib-1.1.1 ext/dlib-19.4/examples/sockets_ex.cpp
dlib-1.1.0 ext/dlib-19.4/examples/sockets_ex.cpp
dlib-1.0.3 ext/dlib-18.13/examples/sockets_ex.cpp
dlib-1.0.2 ext/dlib-18.13/examples/sockets_ex.cpp
dlib-1.0.1 ext/dlib-18.13/examples/sockets_ex.cpp
dlib-1.0.0 ext/dlib-18.13/examples/sockets_ex.cpp