Sender
====================================================================================================
// Create tcp async instance via factory class
auto client = ikCNetClientFactory::CreateClient(Inklude::NET_OPTION::TCP_ASYNC);
// If you don't want to use this instance to receive data, you don't need to provide port number.
client->Initialize();
// You should put destination information. i.e., ip address (domain name) and port number.
client->SetDestinationAddress("127.0.0.1", 9999);
char *buffer = new char[60000];
srand(time(NULL));
// This is to make async handler function using lambda expression.
// If you're not familiar to this expression, you can learn it
// (a lot of resources on the web)
// or just copy & paste is possible.
ikINetClient::AsyncHandler handler;
handler.reset(new std::function<void(size_t)>([&](size_t recvSize)
{
// In here, you can put what you want to do after sending data.
int count = rand() % 23432;
sprintf(buffer, "this is #%d\n", count);
printf(buffer);
Sleep(500);
// In here, just send data again again and again.
client->Send(buffer, 6000, handler);
}
));
client->Send(buffer, 6000, handler);
// This is main thread code.
// This is to maintain this thread (not for ending the app)
while(true)
{
Sleep(1000);
printf("This is main thread\n");
}
Receiver
====================================================================================================
// Create tcp async instance via factory class
auto client = ikCNetClientFactory::CreateClient(Inklude::NET_OPTION::TCP_ASYNC);
// The port number you put in here becomes the port a remote host can access.
client->Initialize(9999);
char *buffer = new char[60000];
srand(time(NULL));
// This is to make async handler function using lambda expression.
// If you're not familiar to this expression, you can learn it
// (a lot of resources on the web)
// or just copy & paste is possible.
ikINetClient::AsyncHandler handler;
handler.reset(new std::function<void(size_t)>([&](size_t recvSize)
{
// In here, you can put what you want to do after receiving data.
printf(buffer);
// In here, just receive data.
client->Receive(buffer, 6000, handler);
}
));
client->Receive(buffer, 6000, handler);
// This is main thread code.
// This is to maintain this thread (not for ending the app)
while(true)
{
Sleep(1000);
printf("This is main thread\n");
}