News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Network problem

Started by Danesh, August 22, 2006, 12:40:48 AM

Previous topic - Next topic

Tedd

I don't think you should need to wait for the (application at the) other side to be ready to receive (or send, when receiving.)
Messages are buffered at either side by winsock, so the other side can be considered always ready - if it's not then the call will fail anyway.

When "send" returns successfully, all this means is that winsock has buffered your message has made a start on sending it. TCP provides 'connections' and so when you do a send, winsock knows it's being received on the other side - so the send call returns successfully.
When "recv" returns successfully, it means the message has been copied from winsock's buffer into yours. The actual message may have already been there (waiting in winsock's buffers) 20 seconds before you even call recv. Or, it could be that there was no message immediately and so your call waits until there is one, and you receive that.

So you shouldn't have any problems with synching between server and clients, as this is handled invisibly already.

I think the problem in this case is that the sockets are running on the same local machine. As a result, send could complete (on the 'other' end) even before it returns successfully. The problem itself could be a mixed consequence of this kind of shortcut - which should only result when the two are both running on the same machine.
So, what you need to do is test it across two separate machines, and see if you can reproduce this strange effect at all. If not, then this is probably what's causing it, and you can assume your program is 'correct.' (Assuming it's meant for multiple machines.)
No snowflake in an avalanche feels responsible.

Danesh

P1: Sure I will share with everybody if I could come to any solution.

Tedd: I tested server and client programs on seprate machines and as I expected the problem still exists. In my tests, I ran the server on my notebook and client from my system. When I press enter (on client side) and hold it (it sends data countinously) it strats to get "Message 1" from server which seems to be good but after few seconds it send "Message 2" and then after few seconds "Message 1" and so on.

D.

Tedd

Forget this headache :bdg
Learn how to use WSAAsyncSelect. The you can receive a message when the data has been received, which should avoid this problem.
No snowflake in an avalanche feels responsible.

P1

Quote from: Tedd on August 24, 2006, 12:50:05 PMLearn how to use WSAAsyncSelect. The you can receive a message when the data has been received, which should avoid this problem.
Exactly !!!   :U

I was checking up on SOCK_STREAM from a M$ source and it's not pretty.  Reminds me of the old serial stuff that I had done.

Regards,  P1  :8)

Danesh

#19
Sure. I will try WSAAsyncSelect.

Thanks P1 and Tedd. You showed me the way.