#include "SocketException.h"
#include <string>
int main ( int argc, int argv[] )
{
try
{
// Create the socket
ServerSocket server ( 30000 );
while ( true )
{
ServerSocket new_sock;
server.accept ( new_sock );
try
{
while ( true )
{
std::string data;
new_sock >> data;
new_sock << data;
}
}
catch ( SocketException& ) {}
}
}
catch ( SocketException& e )
{
std::cout << "Exception was caught:" << e.description() << "\nExiting.\n";
}
return 0;
}
#include "SocketException.h"
#include <iostream>
#include <string>
int main ( int argc, int argv[] )
{
try
{
ClientSocket client_socket ( "localhost", 30000 );
std::string reply;
try
{
client_socket << "Test message.";
client_socket >> reply;
}
catch ( SocketException& e) {}
std::cout << "We received this response from the server:\n\"" << reply << "\"\n";;
}
catch ( SocketException& e )
{
std::cout << "Exception was caught:" << e.description() << "\n";
}
return 0;
}
prompt$ make
prompt$ ./simple_server
running....
second prompt:
prompt$ ./simple_client
We received this response from the server:
"Test message."
prompt$
![http://tldp.org/LDP/LG/gx/note.gif](file:///D:/Users/ADMINI%7E1/AppData/Local/Temp/msohtmlclip1/01/clip_p_w_picpath001.gif)