Hello !
I'm working on a chat server/client application and I've got some problem with the CloseNetworkConnection function.
When a client send "QUIT" to my server, I use CloseNetworkConnection(ClientID) (for example, clientid = 1904). No problem here. But if the same client reconnect (same ip ? No sure, i'm working localy), there are problem with his new clientid. The "Case 1" told me that the ClientID is 1908, but when the client send something, "Case 2" told me that his clientID is 1904...
But, if the client disconnect by himself (= "Case 4" for server), everything work good ..
Any idea ?
Problem with CloseNetworkConnection
I tried to manually set ClientID to 0, but it don't change anything ...
Simplified code :
Simplified code :
Code: Select all
If InitNetwork() = 0
MessageRequester("Error", "Can't initialize the network !", 0)
End
EndIf
Port = 7000
Buffer = AllocateMemory(1000)
; ------------------------------------------------------
; ------------------------------------------------------
OpenConsole()
If CreateNetworkServer(Port)
PrintN("Server created (Port "+Str(Port)+").")
Else
PrintN("Server cannot be open (port in use?)")
Delay(3000)
End
EndIf
Repeat
SEvent = NetworkServerEvent()
If SEvent
ClientID = NetworkClientID()
Select SEvent
Case 1
PrintN("New connection: " +Str(ClientID))
SendNetworkString(ClientID, "HELO"+Chr(10)+Chr(13))
Case 2
ReceiveNetworkData(ClientID, Buffer, 1000)
Debug NetworkClientID()
PrintN("New data from "+Str(clientID))
PrintN(PeekS(Buffer))
; ------------------------------------------------------
; # QUIT
; ------------------------------------------------------
If (StringField(PeekS(Buffer), 1, Chr(10)) = "QUIT")
CloseNetworkConnection(ClientID)
EndIf
Case 3
Debug "receiving a file from: "+Str(clientID)
Case 4
Debug "quit: "+Str(ClientID)
; fin du <Select>
EndSelect
; fin du <If>
EndIf
Until Quit = 1
End