// sockethello.cpp
#include <iostream> #include "SocketClass.h" //These must be set in SocketClass.h #define LINUX //define our OS as linux #define CONCURRENT //use the concurrent server model using namespace std; int main(int argc, char *argv[]) { SocketClass MyServer; //new instance of socketclass int mysocket, theirsocket; //store the ID of our socket and theirs // (so we know where to write to) //We define our server to use the defaults in the class // the socket is bound to all address // and is listening on port DEFAULT_PORT mysocket = MyServer.SocketAlloc(); //Allocate the socket theirsocket = MyServer.ServerOpenSocket(mysocket); //Open the socket, does not return until a client connects MyServer.setSendBuffer(theirsocket, "Hello World\n"); //Fill the buffer with the data to send MyServer.SendData(theirsocket); //Send the data MyServer.RecvData(theirsocket, 10); //Receive their 10 character response cout << MyServer.getRecvBuffer(theirsocket); //print their response MyServer.CloseSocket(); //close our socket return 0; //~SocketClass destructor is called automatically and makes sure all is in order }