An example of how to use the Async::TcpServer class
#include <iostream>
using namespace std;
class MyClass : public sigc::trackable
{
public:
MyClass(void)
{
mem_fun(*this, &MyClass::onClientConnected));
server->clientDisconnected.connect(
mem_fun(*this, &MyClass::onClientDisconnected));
cout << "Connect using: \"telnet localhost 12345\" from "
"another console\n";
}
~MyClass(void)
{
delete server;
}
private:
{
con->
dataReceived.connect(mem_fun(*
this, &MyClass::onDataReceived));
con->
write(
"Hello, client!\n", 15);
}
{
}
{
char *str = static_cast<char *>(buf);
string data(str, str+count);
cout << data;
string dataOut = string("You said: ") + data;
server->
writeOnly(con, dataOut.c_str(), dataOut.size());
{
dataOut = string("He said : ") + data;
server->
writeExcept(con, dataOut.c_str(), dataOut.size());
dataOut = string("To all : ") + data;
server->
writeAll(dataOut.c_str(), dataOut.size());
}
return count;
}
};
int main(int argc, char **argv)
{
MyClass my_class;
}