Listing 3: Simple client program that sends a message using the TCPSocketWrapper class
#include "Sockets.h" #include <iostream> #include <cstring> using namespace std; int main() { if (socketsInit() == false) { cout << "cannot initialize sockets library" << endl; return 0; } try { const char *message = "Hello, Socket!"; int msglen = strlen(message) + 1; TCPSocketWrapper sock; // connect to the same machine // and the IP port of the server process sock.connect("127.0.0.1", 12345); sock.write(message, msglen); } catch (const SocketRunTimeException &e) { cout << "socket exception: " << e.what() << endl; } socketsEnd(); return 0; } End of Listing