Informació general
Exemples
Pantallas
Comparacions
Aplicacions
Descarregar
Documentation
"El Mercat"
Estat i Pla de treball
Preguntes més freqüents
Autors i Llicència
Fòrums
Finançament de l'U++
Cerca en aquesta web
Llengua
català











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");

        }

    }

}

 

 

 

 

Aquesta pàgina també està en english, čeština, deutsch, español, euskara, français, română, русский, 中文(简体) i 中文(繁體). Vols col.laborar?