 ~Sockets~
|
C++ Socket library tutorial
|
|
Using the DisplaySocket as a Server
Server implementation
To use a Socket class in a server program, a template class inherited from
the Socket class is used. An instance of ListenSocket<class X> can be bound
to a listen port using the Bind() method.
Incoming connections are accepted by the ListenSocket, and a Socket class of
type X is created and automatically added to the SocketHandler.
displayserver.cpp
#include <SocketHandler.h>
#include <ListenSocket.h>
#include "DisplaySocket.h"
static bool quit = false;
int main()
{
SocketHandler h;
ListenSocket<DisplaySocket> l(h);
if (l.Bind(9001))
{
exit(-1);
}
h.Add(&l);
h.Select(1,0);
while (!quit)
{
h.Select(1,0);
}
}
|
|
|