Page 1 of 1

New networking command needed for Threads

Posted: Thu Sep 06, 2012 2:40 am
by RichAlgeni
When working with threads and server sockets, the existing command NetworkServerEvent() is inadequate. It does not give you enough information as it does not allow interrogation per EventClient().

I'd like to propose a new command: Result = NetworkConnectionEvent(EventClient()).

You would pass the EventClient() to this command, and information about specific connection would be returned to you. The returned result could use the same numbering scheme returned by NetworkServerEvent(), with the exception that it could never return #PB_NetworkEvent_Connect.

I believe that this is a very important requirement. I've been testing networking extensively, and it's my belief that sever sockets in threads cannot be done correctly with PureBasic alone as it is now. I am currently using the Windows API command ioctlsocket_() to return information about a socket in a thread.

Re: New networking command needed for Threads

Posted: Thu Sep 06, 2012 2:03 pm
by swhite
I do not have a lot of experience with sockets in multiple threads but when I tried it I got some very strange results. It seamed to me that the multiple threads could process data from the same connection because of the way NetworkServerEvent() works, which obviously was not good as each might only receive part of the data or receive data that another thread was expecting. So I am in agreement that some enhancements might be needed to make handling sockets in threads much easier. In particular you need to be able to ensure that you are processing events for a specific client within the thread.
As I have suggested in the Enhancement Requests the whole networking section needs much more detailed information in the help file.

Re: New networking command needed for Threads

Posted: Fri Sep 07, 2012 9:39 pm
by Warmonger
I agree, ReceiveNetworkData() should not return -1 every time it receives no data. It should always return the amount of data received 0-65535. And only -1 when a real error occurs. It would also be nice to see at least a basic set of returned error codes for it as well.

See here => http://purebasic.fr/english/viewtopic.p ... 30#p390130