I am a little puzzled by an aspect of ReceiveNetworkData(). When used by a client without a client event loop (i.e. without using NetworkClientEvent() etc.) then this function seems to block execution in the case that the server has not sent any data and has not closed the connection.
I am puzzled because I know that PB uses non-blocking sockets.
Is this behaviour to be expected and should I thus definitely use a client event loop? The reason I ask is because, for the client, I would prefer not to use a client event loop.
Test code...
Server.
Code: Select all
If InitNetwork() = 0
MessageRequester("Error", "Can't initialize the network !", 0)
End
EndIf
Port = 6509
If CreateNetworkServer(0, Port)
MessageRequester("PureBasic - Server", "Server created (Port "+Str(Port)+").", 0)
Repeat
Delay(1)
SEvent = NetworkServerEvent()
If SEvent
ClientID = EventClient()
Select SEvent
Case #PB_NetworkEvent_Connect
Debug "A new client has connected!"
Case #PB_NetworkEvent_Disconnect
Debug "Client has disconnected!"
Quit = 1
EndSelect
EndIf
Until Quit = 1
CloseNetworkServer(0)
Else
MessageRequester("Error", "Can't create the server (port in use ?).", 0)
EndIf
Client.
Code: Select all
If InitNetwork() = 0
MessageRequester("Error", "Can't initialize the network !", 0)
Else
Port = 6509
*buffer = AllocateMemory(1000)
ConnectionID = OpenNetworkConnection("localhost", Port)
If ConnectionID
Debug "About to call ReceiveNetworkData() ......"
ReceiveNetworkData(ConnectionID, *Buffer, 40)
Debug "ReceiveNetworkData() has returned!"
CloseNetworkConnection(ConnectionID)
Else
MessageRequester("PureBasic - Client", "Can't find the server (Is it launched ?).", 0)
EndIf
EndIf



