Información general
Ejemplos
Pantallas
Comparaciones
Aplicaciones
Descargar
Documentation
"El Mercado"
Estado y Plan de trabajo
Preguntas más frecuentes
Autores y Licencia
Foros
Financiación de U++
Busca en esta página
Idioma
español











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

        }

    }

}

 

 

 

 

Esta página está también en english, català, čeština, deutsch, euskara, français, română, русский, 中文(简体) y 中文(繁體). ¿Quieres ayudar?