A C++ Socket Library for Linux
by Jason But

Listing One
try
{
    IPAddress       cClientIP;
    int             iClientPort;
    SocketBase      cListenSock(), cCommsSock;

    // Bind listening socket to port 80 and start listening for a connection
    cListenSock.Bind(80);
    cListenSock.Listen(5);

    // Block until a client connects, cCommsSock now refers to 
    //    the newly connected socket
    cListenSock.Accept(&cCommsSock, cClientIP, iClientPort);

    printf("Client (%s) connected from port %d\n", 
                         (const char *) cClientIP, iClientPort);
    // Data transfer using cCommsSock
    cCommsSock.Recv(..);
    cCommsSock.Send(..);

    // cListenSock and cCommsSock are closed when they go out of scope
}
catch (SocketException &excep);
{
    printf("Error in Socket Call : %s\n", (const char *) excep);
}




1

