954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

When is the RST sent over a tcp socket?

Hi,

My webserver code is trying to send an image file over a TCP connection. However, the send() function is returning a -1 value with the error: Connection Reset by peer. I am using a web-browser to access the server so my guess is that the server is somehow sending the RST flag to the client which is causing the termination of connection.

I am only new to socket programming so I was wondering if you could help me understand the RST packet and how it works. How can I program the server side socket to ensure that the connection is kept alive and that the RST flag is not sent.

Thanks heaps!

bnickerson
Newbie Poster
9 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

Are you having a problem only with image data or even with simple data as well ?
The RST flag is usually raised when a host receives a packet which does not belong to the current connection.

abhimanipal
Master Poster
742 posts since Dec 2009
Reputation Points: 114
Solved Threads: 104
 
Are you having a problem only with image data or even with simple data as well ? The RST flag is usually raised when a host receives a packet which does not belong to the current connection.

The text files are being sent fine. I am trying to send a file that has two images embedded in it. The webpage is sent however the send() function returns a -1 value when attempting to the image. The error says: Connect reset by peer. I have even enabled the TCP_Keep_alive option in setsockopt but still no difference :s

bnickerson
Newbie Poster
9 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

I think the problem is that you are trying to send images rather than being a N/W problem.

Maybe this will be of help

abhimanipal
Master Poster
742 posts since Dec 2009
Reputation Points: 114
Solved Threads: 104
 

I think the problem is that you are trying to send images rather than being a N/W problem.

Maybe this will be of help

But everything else works fine though? Here is the code I am using to send the images:

//copy file into the buffer
			while(!feof(sendFile)){
				bzero(send_buffer,MAX_MSG);
                //result = fread (send_buffer,1,sizeof(send_buffer),sendFile);
				while(result>0){
					result = fread (send_buffer,1,sizeof(send_buffer),sendFile);
					printf("Result value is %d\n",result);
					if(ferror(sendFile)){
						printf("ERROR: %s\n", strerror(errno));
						printf("Error reading file: %s\n",request_page);
					}
					if((test=send(new_fd,send_buffer,sizeof(send_buffer),0))<0){
						printf("ERROR: %s\n", strerror(errno));
				  	    printf("Sending %s Failed\n", request_page);
					    exit(1);
					}
					printf("Sending worked\n");
					bzero(send_buffer,sizeof(send_buffer));
				}
			}
			fclose(sendFile);
bnickerson
Newbie Poster
9 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

What is the value of result ?
Are you sure new_fd is initialized correctly ?

abhimanipal
Master Poster
742 posts since Dec 2009
Reputation Points: 114
Solved Threads: 104
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: