Problem with CloseNetworkConnection

Just starting out? Need help? Post your questions and find answers here.
pfoo
New User
New User
Posts: 7
Joined: Thu May 25, 2006 3:00 pm

Problem with CloseNetworkConnection

Post by pfoo »

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 ?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

One of the things you need to make sure that if clientid is a global or in a link list and not removed, you need to manually set it to 0 after disconnecting the client. I found this out the hard way.
pfoo
New User
New User
Posts: 7
Joined: Thu May 25, 2006 3:00 pm

Post by pfoo »

I tried to manually set ClientID to 0, but it don't change anything ...

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
pfoo
New User
New User
Posts: 7
Joined: Thu May 25, 2006 3:00 pm

Post by pfoo »

Note : I'm still using v3.94 windows (waiting for PB 4.0 linux before downloading v4)
Post Reply