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











SourceForge.net Logo



SocketServer

 

Example of using server Socket - its counterpart is SocketClient

 

 

SocketServer.cpp

 

#include <Web/Web.h>

 

using namespace Upp;

 

CONSOLE_APP_MAIN

{

    Socket server;

    if(!ServerSocket(server, 3214)) {

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

        SetExitCode(1);

        return;

    }

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

    for(;;) {

        Socket s;

        if(server.Accept(s)) {

            String w = s.ReadUntil('\n');

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

            if(w == "time")

                s.Write(AsString(GetSysTime()));

            else

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

            s.Write("\n");

        }

    }

}

 

 

 

 

This page is also in català, čeština, deutsch, español, euskara, français, română, русский, 中文(简体) and 中文(繁體). Do you want to contribute?