IonicWind Software

IWBasic => Network Client/Server programming => Topic started by: JoaoAfonso on December 04, 2008, 05:24:15 PM

Title: First doubt!
Post by: JoaoAfonso on December 04, 2008, 05:24:15 PM
Good evening!
I am doing a game using EB and used winsock library directly. I am now converting it to the new NCS code, which will make everything abit more ease and clear.

Watching the example projects, I see this piece of code I do not understand the purpose:

if DataSockets[client] > -1
'rearm the registered data message
NCSOnDataMessage(cserver.hwnd,DataSockets[client],msg_clientDataFirst+client)
endif


Can someone clarify?
Thanks in advance
Title: Re: First doubt!
Post by: Ionic Wind Support Team on December 04, 2008, 05:39:32 PM
When you register a message to be sent to your handler the Winsock library will only call the message when data is initially available, and again until all the data requested has been received.  So the code re-registers the message after data has been received to ensure it continues to call your handler.

Microsoft explains it better:

Quote
The Windows Sockets DLL will not continually flood an application with messages for a particular network event. Having successfully posted notification of a particular event to an application window, no further message(s) for that network event will be posted to the application window until the application makes the function call which implicitly re-enables notification of that network event.

If you try out the chat demo, comment out that rearming code and see what happens.  After the initial chat message the window stops receiving data message events.

Title: Re: First doubt!
Post by: Ionic Wind Support Team on December 04, 2008, 05:41:20 PM
I should note that NCSOnDataMessage and NCSOnConnectMessage use the function WSAAsyncSelect in case you want to study it further ;)
Title: Re: First doubt!
Post by: JoaoAfonso on December 04, 2008, 06:03:26 PM
Ah! Thought something like that, but couldn't figured out.
Thanks!
Title: Re: First doubt!
Post by: Ionic Wind Support Team on December 04, 2008, 06:14:16 PM
Your welcome.  Took me by surprise too when I first coded it, as the message would work for the first couple of packets and then nothing.  Microsoft doesn't really emphasize that you have to reenable the message, just a couple of sentences at the end of the function description.

Paul.