Socket programming problems
hi
I'm trying to debug a small C++ routine that connects to a listening socket (on another machine) and sends/receives messages. This should be a simple task but I've come across incredible problems which I can't sort out. The routine is like this: a) I connect to the listening socket using connec() b) Send message on that socket c) Use select() to wait for response from the peer d) Send message again on the same socket (ignoring the select() return) e) loop like this until I say stop!!!! The problem lies in part d). It never sends the data for the second time and onwards eventhough the send() function doesn't return any error. It seems so that I can only send data once on a connecting socket. Is that correct or am I not doing this right?? Here is the while loop doing the send(),select() and recv() Code:
while (1) Code:
regards Marri |
Hi,
This may not be causing any problems but I noticed that you are using sizeof(cBuffer) as the third argument to send. It looks to me that it should be sizeof(sSendBuffer). cout << "bytes sent: " << send(iSocket, sSendBuffer, sizeof(cBuffer), 0) << endl; |
thanks for the reply.
But the cBuffer is defined as follows: char cBuffer[512]; and then the sSendBuffer is defined as follows: char* sSendBuffer = cBuffer; this definition does the same as malloc(). One other thing, Could it be that the recv() call, made by the server, is closing the socket after receiving ???? Is that standard configuration and if so, how can it be changed. regards Einar |
The following program is your code combined into a single function: test() . I ran it on my local machine and ran "netcat -l -p 20000" to act as a server. This seemed to work fine.
You might want to try this as well on your machine. If it works, then the problem probably is that your remote server is not behaving as you expect. To answer your question, resetting the socket after a recv is not default behavior but the server could do it anyway for some reason. Tcpdump ad/or ethereal might give you some useful diagnostics. - Dave Code:
#include <stdio.h> |
hi
this is a tcp buffer problem and I have tried pretty much everything to work around it so I wan to ask how is it best to ensure instant delivery using tcp sockets. I know that many people have had this problem and I've followed those instructions I have read but without any result. I check the result from recv() and send() to insure that everything has been received and sent. But the send() function always halts after the second time,,,,, Hope somebody has had similar problems and SOLVED it. Marri |
setsockopt (TCP_NODELAY)?
|
All times are GMT -5. The time now is 05:45 PM. |