#include <iostream>
using namespace std;
class MyClass : public sigc::trackable
{
public:
MyClass(void)
{
con->connected.connect(mem_fun(*this, &MyClass::onConnected));
con->disconnected.connect(mem_fun(*this, &MyClass::onDisconnected));
con->frameReceived.connect(mem_fun(*this, &MyClass::onFrameReceived));
con->connect();
}
~MyClass(void)
{
delete con;
}
private:
void onConnected(void)
{
cout <<
"Connection established to " << con->
remoteHost() <<
"...\n";
size_t bufsize = 10000000;
char *buf = new char[bufsize];
for (size_t i=0; i<bufsize; ++i) { buf[i] = i & 0xff; }
cout << "Sending 3x frames to the server..." << endl;
con->
write(buf, bufsize/4);
con->
write(buf, bufsize/2);
con->
write(buf, bufsize);
cout << "Sending QUIT to server" << endl;
delete [] buf;
}
{
cout <<
"Disconnected from " << con->
remoteHost() <<
"...\n";
Application::app().quit();
}
{
char *str = reinterpret_cast<char *>(frame.data());
string html(str, str+frame.size());
cout << html;
}
};
int main(int argc, char **argv)
{
MyClass my_class;
}
The core class for writing asyncronous cpp applications.
A TCP connection with framed instead of streamed content.
Contains a class for creating TCP client connections.
An application class for writing non GUI applications.
void exec(void)
Execute the application main loop.
A TCP connection with framed instead of streamed content.
A class for creating a TCP client connection.
const IpAddress & remoteHost(void) const
Return the IP-address of the remote host.
DisconnectReason
Reason code for disconnects.
virtual int write(const void *buf, int count)
Write data to the TCP connection.
Namespace for the asynchronous programming classes.