Show server_socket.cc syntax highlighted
#include <exception>
#include <string>
#include <iostream>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include "Socket.h"
using namespace std;
using namespace Net;
int main(int argc, char **argv)
{
try {
ServerSocket server("127.0.0.1", "4321");
Socket *s;
std::string line;
struct timeval t;
while(s = server.accept()) {
while(true) {
try {
t.tv_sec = 5;
t.tv_usec = 0;
line=s->getLine(&t);
cout << "Client says: " << line;
} catch(std::exception &e) {
cout << "Client connection done: " << e.what() << endl;
break;
}
}
}
} catch(exception &e) {
cerr << e.what() << endl;
}
return 0;
}
See more files for this project here