WSASend returns 10054

Hi all,

I am working on socket programming. I am using asynchronous socket APIs to send and receive.
When I have WSARecv and WSASend functions in the same function, the data gets transferred properly; whereas if i separate send and receive functions, while sending the data I am getting error 10054 (connection reset by peer).

The _send_data() function has 2 parameters, the data and the socket where to send the data.

Can anyone tell me the reason why this is happening ?

Any help would be appreciated.
The other side has terminated the connection.
Yes. The connection gets terminated. But when I have WSARecv & WSASend apis in the same function, the connection does not terminate and the data transfer happens properly.

The connection resets in the following scenario:

void handle_request()
if( received bytes != 0)
send_data(data, send_socket)

void send_data(data, send_socket)
the connection does not terminate and the data transfer happens properly.
Perhaps, you should think of it as transferring data until the connection terminates, rather than transferring data if you happen not to get the termination.

You need to revise the protocol between the server and client and make sure they both agree on the termination conditions.
can you please explain how can i go with that ?
Right now I am using select() function to check the status of the socket, whether it is ready to write or not. Is there any other mechanism by which I will get the status of the socket.
Basically I am write a client server application which plays a video file in Media player. It receives a request from browser. After receiving that request, the socket I get is from the media player and I write the data to this socket.
How this new socket connection from media player affects the data transfer using async operations ?
Forget the code for now. Write down two columns, one for the server and the other for a client. Then write what message is sent first, what's send next and so on until they're done.

That is your protocol. There should be a clear initialisation sequence and a clear termination sequence. When you don't do that, it all goes bad and one party terminates the conversation while the other isn't expecting it.

It's sort of like you going to a Bank to deal with a cashier about making a deposit. And just before you hand over your the money, the cashier closes the desk and goes for lunch, leaving you standing there. That's what's happening in your program.
Last edited on
Topic archived. No new replies allowed.