Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site











SourceForge.net Logo

SocketServer

 

Example of using server Socket - its counterpart is SocketClient

 

 

SocketServer.cpp

 

#include <Core/Core.h>

 

using namespace Upp;

 

CONSOLE_APP_MAIN

{

    TcpSocket server;

    if(!server.Listen(3214, 5)) {

        Cout() << "Unable to initialize server socket!\n";

        SetExitCode(1);

        return;

    }

    Cout() << "Waiting for requests..\n";

    for(;;) {

        TcpSocket s;

        if(s.Accept(server)) {

            String w = s.GetLine();

            Cout() << "Request: " << w << " from: " << s.GetPeerAddr() << '\n';

            if(w == "time")

                s.Put(AsString(GetSysTime()));

            else

                s.Put(AsString(3 * atoi(~w)));

            s.Put("\n");

        }

    }

}

 

 

 

 

Do you want to contribute?