Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void* run() {
- // Remove 1 item at a time and process it. Blocks if no items are
- // available to process.
- //Client declaration
- 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()));
- //Client declaration ends
- for (int i = 0;; i++) {
- printf("thread %lu, loop %d - waiting for item...\n",
- (long unsigned int)self(), i);
- WorkItem* item = m_queue.remove();
- printf("thread %lu, loop %d - got one item\n",
- (long unsigned int)self(), i);
- TCPStream* stream = item->getStream();
- // Echo messages back the client until the connection is
- // closed
- //char input[256];
- char input[1024]; //changed from 256 to 1024
- char line[1024];
- memset(line,'\0',sizeof(line));
- memset(input,'\0',sizeof(input));
- int len;
- while ((len = stream->receive(input, sizeof(input)-1)) > 0 ){
- input[len] = NULL;
- //Code Addition by Srini starts here
- //Client declaration
- //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()));
- //Client declaration ends
- if (stream_client)
- {
- stream_client->send(input, sizeof(input));
- printf("sent - %s\n", input);
- len = stream_client->receive(line, sizeof(line));
- line[len] = NULL;
- printf("received - %s\n", line);
- delete stream_client;
- }
- //Code Additon by Srini ends here
- stream->send(line, len);
- printf("thread %lu, echoed '%s' back to the client\n",
- (long unsigned int)self(), line);
- }
- delete item;
- }
- // Should never get here
- return NULL;
- }
Add Comment
Please, Sign In to add comment