March 29, 2024, 04:13:46 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


First doubt!

Started by JoaoAfonso, December 04, 2008, 05:24:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JoaoAfonso

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
JoÃÆ'ƒÂÃ,£o Afonso
Viriato
-----------------
Iberia MUD
www.iberiamud.com
iberiamud.com:5900

Ionic Wind Support Team

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.

Ionic Wind Support Team

Ionic Wind Support Team

I should note that NCSOnDataMessage and NCSOnConnectMessage use the function WSAAsyncSelect in case you want to study it further ;)
Ionic Wind Support Team

JoaoAfonso

Ah! Thought something like that, but couldn't figured out.
Thanks!
JoÃÆ'ƒÂÃ,£o Afonso
Viriato
-----------------
Iberia MUD
www.iberiamud.com
iberiamud.com:5900

Ionic Wind Support Team

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.
Ionic Wind Support Team