I am trying to connect client socket to server socket only once when program starts. After that it should only send and receive.
Also I written this client program inside my server socket.Since my requirement is my server will receive some data from original client and send same data(as client) to another server and receive from server and send same data to original client
Three things are
1. Original client(Some device which act as client you can say)
2. Server(which also contains client like program in thread to send and receive)
3. External Server( Which I will hit from second step)
The code I am having for second step is shown below link.
https://pastebin.com/UmPQJ70w
My question is more related to C++ Where exactly I need to put below code in program.
Code:
TCPConnector* connector_client = new TCPConnector();
printf("ip_client = %s\tport_client = %s\tport_client_int = %d\n", ip_client.c_str(), port_client.c_str(),atoi(port_client.c_str()));
TCPStream* stream_client = connector_client->connect(ip_client.c_str(), atoi(port_client.c_str()));
-- If I am writing inside While loop it works but it connect every time.
-- If I write outside for loop as shown in paste bin. It works only one time after that due to delete stream_client; as shown below in code. If I remove delete stream_client it works but memory will not free.
Code:
-------
-------
--------
len = stream_client->receive(line, sizeof(line));
line[len] = NULL;
printf("received - %s\n", line);
delete stream_client;
So what is the smartest way I can handle in my application.