hi all,

i just finished a (working) little client-server-prog.
Two primitive programs just to show how it may work.
Both server and client create a simple window (don't ask me why, maybe dialogs would be better?), both create sockets. For example, you start the server and it will say something like "initialization ok"...after that, it waits for incoming connections.

Now i start the Client, and it responds immediately to the waiting server (receives FD_WRITE).
Accordingly, it starts the sending procedure. Twice.:confused:
Then, if you click left mouse in the Client window, you may send again - as it should be.

My problem is: I don't know why the Client sends twice at startup. Do you know how to avoid that?

Another thing is the missing FD_CONNECT message.
Maybe it's not missing, but i only get it if i start the Server when the Client is already running.

Any comment is highly appreciated



thankyou in advance
Posted on 2001-12-17 13:04:16 by sys64738
You have problems with the same thing as many winsock beginners. Try to get a better understanding of WSAAsyncSelect and it's notification messages (FD_READ, FD_WRITE and so on).
An important thing that most beginners tend to forget is that those messages are just notification messages that tell you a specific network event has happened.
That's it, nothing more.
When you want to send data to the server, you need to time when and which data you want to send.
FD_WRITE isn't the right trigger for this. FD_WRITE just means: "The other side is ready for writing again". Nothing more. So everytime the other side is ready for writing, you are sending the same data. That's of course not what you want. I've marked the word 'again' above because FD_WRITE is sent everytime the other side is ready for writing again since you last sent something. So after you sent your data, the message is sent again and that's why your data is sent twice.

The right way to use winsock is to carefully plan when you want to send or receive something. I really recommend you to read the documentation of WSAAsyncSelect carefully, there's a lot explained at that page, as well as these threads:

http://www.asmcommunity.net/board/index.php?topic=2086

http://www.asmcommunity.net/board/index.php?topic=2326

Thomas
Posted on 2001-12-17 14:40:22 by Thomas
:grin:
ok i think i understand what you mean. thank you for the hint.
Iczelion for example uses a method to determine the size of the content which will be sent and delivers that amount of bytes,
basically the same method that you suggest in the other thread. Correct?
Anyway, that makes much more sense when i think about it.
I'll try your method.

But what about the FD_CONNECT?
Does the Client receive this message at all when the specific amount of bytes was sent?
Do i have to send data until some counter tells me that all my data has been sent?

Let's say I want to send 30000 bytes, so I invoke SEND, and SEND returns 19000. Obviously not enough. So, i have to SEND it all again until the 30000 bytes are transmitted(?), or is it enough to send just the "rest", like starting from 19001 up 30000 and repeat this as long as necessary?

sorry, but :stupid:
Posted on 2001-12-17 15:10:40 by sys64738

ok i think i understand what you mean. thank you for the hint.
Iczelion for example uses a method to determine the size of the content which will be sent and delivers that amount of bytes,
basically the same method that you suggest in the other thread. Correct?


Yes, you have to be sure about how many bytes you want to send, and how many bytes were actually sent.

Anyway, that makes much more sense when i think about it.
I'll try your method.

But what about the FD_CONNECT?
Does the Client receive this message at all when the specific amount of bytes was sent?


No, it tells you the socket has just connected to some server. The problem was the messagebox you showed in your WM_SOCKET handler:


invoke MsgBox, hWnd, addr SockDATA


I think messageboxes mess up the window procedure. When you comment the above line, it will work. I've seen this happen before, try to avoid messageboxes on network events.



Do i have to send data until some counter tells me that all my data has been sent?


Yes that's correct. Otherwise you wouldn't know *if* and *how much* data was actually sent.


Let's say I want to send 30000 bytes, so I invoke SEND, and SEND returns 19000. Obviously not enough. So, i have to SEND it all again until the 30000 bytes are transmitted(?),


No, because you would send the first 19000 bytes again. It's very unlikely that you can send 30000 bytes with one send call. Try to do say 1024 bytes at a time (every send call).

or is it enough to send just the "rest", like starting from 19001 up 30000 and repeat this as long as necessary?


Yes that's what you need. The return value of send indicates how many bytes *really* have been sent. Add this to your 'current number of bytes already sent'-counter. Then wait for the next FD_WRITE msg. Every time you call send, the FD_WRITE message is reactivated (I explained this in detail in the other thread), so it will be sent again as soon as the other side is ready for writing again (which may be immediately). So don't just 'loop' send until all data has been transmitted, as each call to send would cause an FD_WRITE msg to be sent. I've explained a lot of this in the nyook's thread.

Thomas
Posted on 2001-12-18 03:59:16 by Thomas
thank you very much Thomas. it's a bit clearer now. ;)
maybe you have seen that i have reserved some lines for the size-problem

so, is there a "safe" place for a messagebox?
what would you do to get info about the current state of connection?

ok greed is not good
you wrote a lot to help me and i appreciate that very much
thank you (again):alright:

cu
Posted on 2001-12-18 11:50:41 by sys64738
Originally posted by sys64738
thank you very much Thomas. it's a bit clearer now. ;)
maybe you have seen that i have reserved some lines for the size-problem

so, is there a "safe" place for a messagebox?
what would you do to get info about the current state of connection?

It seems to work okay when you put them inside the .IFs that check for FD_CONNECT etc, but not before them.
However if you can, avoid them. Somehow they interfere with the window procedure and mess up things.
You can also show a listbox or something like that on your main window, which you can add items too that say 'connected', 'sending data' etc.

Thomas
Posted on 2001-12-18 13:22:52 by Thomas