#include "Sockets.h"
#include <iostream>
using namespace std;
int main()
{
if (socketsInit() == false)
{
cout << "cannot initialize sockets library"
<< endl;
return 0;
}
try
{
char buf[100];
int readn;
TCPSocketWrapper serversocket;
// listen on some port
serversocket.listen(12345);
while (1)
{
cout << "server is ready" << endl;
TCPSocketWrapper sock(sockserver.accept());
cout << "got connection from: "
<< sock.address() << endl;
readn = sock.read(buf, 100);
cout << "read " << readn << " bytes: "
<< buf << endl;
}
}
catch (const SocketRunTimeException &e)
{
cout << "socket exception: "
<< e.what() << endl;
}
socketsEnd();
return 0;
}
End of Listing