Skip to content

Instantly share code, notes, and snippets.

@lucindo
Created September 25, 2010 04:25
Show Gist options
  • Save lucindo/596470 to your computer and use it in GitHub Desktop.
Save lucindo/596470 to your computer and use it in GitHub Desktop.
#include "Event.hh"
#include "TCPSocket.hh"
#include "TCPServer.hh"
#include <string>
#include <iostream>
class EchoSocket : public TCPSocket
{
public:
void onConnect()
{
std::cout << remoteAddr() << ':' << remotePort() << " connected" << std::endl;
}
void onClose()
{
std::cout << remoteAddr() << ':' << remotePort() << " disconnected" << std::endl;
}
void onRead(std::string const & data)
{
this->write(data);
}
};
int main(int, char **)
{
eventSetup();
TCPServer<EchoSocket> server(std::string("127.0.0.1"), 4242);
// server.setup(TCPServer::ASYNC, getNumberOfCores(), TCPServer::THREAD_POOL, 2, 256);
server.start();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment