Hi !
Launch the server code and click "Démarrer le serveur" for starting a server.
Execute client code and click "Connection au serveur" for connection with the server.
But ! when i click on "Déconnection du serveur" for disconnecting from the server, the server quit ???
Error in my client 'type' ???
Server Code :
-------------
Global Window_Width=630
Global Window_Height=215
Global Window_Left=210
Global Window_Top=100
Global Window_Title$="Filax window"
; Declaration d'une fenetre et des boutons
; ----------------------------------------
Global Filax_Window=CreateWindow(Window_Title$,Window_Left,Window_Top,Window_Width,Window_Height,0,1+8)
Global Filax_Bouton01=CreateButton("&Démarrer le serveur",10,10,130,30,Filax_Window)
Global Filax_Bouton02=CreateButton("&Arreter le serveur",10,40,130,30,Filax_Window)
Global Filax_Liste01=CreateListBox( 150,10,230,150,Filax_Window )
Global Filax_Liste02=CreateListBox( 400,10,210,150,Filax_Window )
Global ClientMode=0
Global ServerMode=0
Type NewClient
Field Name$
Field TCPStream
End Type
Global T.NewClient
While Not KeyHit(1)
; ----------------------------
; Boucle de gestion des gadget
; ----------------------------
Select WaitEvent(0)
Case $401
Select EventSource()
Case Filax_Bouton01
If ServerMode=0
ServerStream=CreateTCPServer(8080)
If ServerStream<>0 Then
InsertGadgetItem Filax_Liste01,0,"Démarrage du serveur ok ..." : WaitEvent(0)
ServerMode=1
Else
InsertGadgetItem Filax_Liste01,0,"Impossible de démarrer le serveur ..." : WaitEvent(0)
ServerMode=0
End If
EndIf
Case Filax_Bouton02
If ServerMode=1 Then
InsertGadgetItem Filax_Liste01,0,"Serveur déconnecté ..." : WaitEvent(0)
CloseTCPServer(ServerStream)
ServerMode=0
EndIf
End Select
Case $803
End
End Select
; ---------------------------
; Boucle de gestion du reseau
; ---------------------------
If ServerMode=1 Then
TCPStream=AcceptTCPStream(ServerStream)
If TCPStream Then
TCPString$=ReadString$(TCPStream)
T.NewClient=New NewClient
T\Name$=TCPString$
T\TCPStream=TCPStream
InsertGadgetItem Filax_Liste01,0,"Nouvelle connection ..."+TCPString$ : WaitEvent(0)
Proc_RedrawClientList()
End If
EndIf
Proc_GetClientMessage()
Wend
End
Function Proc_GetClientMessage()
For T.NewClient=Each NewClient
TCPString$=ReadString$(T\TCPStream)
If TCPString$<>"" Then
Select TCPString$
Case "[DISCONNECT]"
TCPString$=ReadString$(T\TCPStream)
InsertGadgetItem Filax_Liste01,0,"Déconnection du client : "+TCPString$ : WaitEvent(0)
Proc_RemoveClient(TCPString$)
Proc_RedrawClientList()
End Select
EndIf
Next
End Function
Function Proc_RedrawClientList()
ClearGadgetItems Filax_Liste02
For T.NewClient=Each NewClient
InsertGadgetItem Filax_Liste02,0,T\Name$ : WaitEvent(0)
Next
End Function
Function Proc_RemoveClient(Name$)
For T.NewClient=Each NewClient
If T\Name$=Name$
CloseTCPStream T\TCPStream
Delete T : Delay 2000
EndIf
Next
End Function
Client Code :
-------------
Global Window_Width=600
Global Window_Height=215
Global Window_Left=410
Global Window_Top=400
Global Window_Title$="Filax window"
; Declaration d'une fenetre et des boutons
; ----------------------------------------
Global Filax_Window=CreateWindow(Window_Title$,Window_Left,Window_Top,Window_Width,Window_Height,0,1+8)
Global Filax_Bouton01=CreateButton("&Connection au serveur",10,10,130,30,Filax_Window)
Global Filax_Bouton02=CreateButton("&Déconnection du serveur",10,40,130,30,Filax_Window)
Global Filax_Bouton03=CreateButton("&Envoyer une phrase",10,70,130,30,Filax_Window)
Global Filax_Liste01=CreateListBox( 150,10,430,150,Filax_Window )
Global ClientMode=0
Global ServerMode=0
Global ClientName$="Filax"
While Not KeyHit(1)
; ----------------------------
; Boucle de gestion des gadget
; ----------------------------
Select WaitEvent(0)
Case $401
Select EventSource()
Case Filax_Bouton01
If ClientMode=0 Then
ClientStream=OpenTCPStream("localhost",8080)
If ClientStream<>0 Then
WriteString ClientStream,ClientName$
InsertGadgetItem Filax_Liste01,0,"Connection au serveur ok ..." : WaitEvent(0)
ClientMode=1
Else
InsertGadgetItem Filax_Liste01,0,"Connection du serveur impossible ..." : WaitEvent(0)
ClientMode=0
End If
EndIf
Case Filax_Bouton02
If ClientMode=1 Then
WriteString ClientStream,"[DISCONNECT]"
WriteString ClientStream,ClientName$
Delay 2000
CloseTCPStream(ClientStream)
InsertGadgetItem Filax_Liste01,0,"Déconnection du serveur ok ..." : WaitEvent(0)
ClientMode=0
EndIf
Case Filax_Bouton03
Delay 1000
End Select
Case $803
End
End Select
Wend
Launch the server code and click "Démarrer le serveur" for starting a server.
Execute client code and click "Connection au serveur" for connection with the server.
But ! when i click on "Déconnection du serveur" for disconnecting from the server, the server quit ???
Error in my client 'type' ???
Server Code :
-------------
Global Window_Width=630
Global Window_Height=215
Global Window_Left=210
Global Window_Top=100
Global Window_Title$="Filax window"
; Declaration d'une fenetre et des boutons
; ----------------------------------------
Global Filax_Window=CreateWindow(Window_Title$,Window_Left,Window_Top,Window_Width,Window_Height,0,1+8)
Global Filax_Bouton01=CreateButton("&Démarrer le serveur",10,10,130,30,Filax_Window)
Global Filax_Bouton02=CreateButton("&Arreter le serveur",10,40,130,30,Filax_Window)
Global Filax_Liste01=CreateListBox( 150,10,230,150,Filax_Window )
Global Filax_Liste02=CreateListBox( 400,10,210,150,Filax_Window )
Global ClientMode=0
Global ServerMode=0
Type NewClient
Field Name$
Field TCPStream
End Type
Global T.NewClient
While Not KeyHit(1)
; ----------------------------
; Boucle de gestion des gadget
; ----------------------------
Select WaitEvent(0)
Case $401
Select EventSource()
Case Filax_Bouton01
If ServerMode=0
ServerStream=CreateTCPServer(8080)
If ServerStream<>0 Then
InsertGadgetItem Filax_Liste01,0,"Démarrage du serveur ok ..." : WaitEvent(0)
ServerMode=1
Else
InsertGadgetItem Filax_Liste01,0,"Impossible de démarrer le serveur ..." : WaitEvent(0)
ServerMode=0
End If
EndIf
Case Filax_Bouton02
If ServerMode=1 Then
InsertGadgetItem Filax_Liste01,0,"Serveur déconnecté ..." : WaitEvent(0)
CloseTCPServer(ServerStream)
ServerMode=0
EndIf
End Select
Case $803
End
End Select
; ---------------------------
; Boucle de gestion du reseau
; ---------------------------
If ServerMode=1 Then
TCPStream=AcceptTCPStream(ServerStream)
If TCPStream Then
TCPString$=ReadString$(TCPStream)
T.NewClient=New NewClient
T\Name$=TCPString$
T\TCPStream=TCPStream
InsertGadgetItem Filax_Liste01,0,"Nouvelle connection ..."+TCPString$ : WaitEvent(0)
Proc_RedrawClientList()
End If
EndIf
Proc_GetClientMessage()
Wend
End
Function Proc_GetClientMessage()
For T.NewClient=Each NewClient
TCPString$=ReadString$(T\TCPStream)
If TCPString$<>"" Then
Select TCPString$
Case "[DISCONNECT]"
TCPString$=ReadString$(T\TCPStream)
InsertGadgetItem Filax_Liste01,0,"Déconnection du client : "+TCPString$ : WaitEvent(0)
Proc_RemoveClient(TCPString$)
Proc_RedrawClientList()
End Select
EndIf
Next
End Function
Function Proc_RedrawClientList()
ClearGadgetItems Filax_Liste02
For T.NewClient=Each NewClient
InsertGadgetItem Filax_Liste02,0,T\Name$ : WaitEvent(0)
Next
End Function
Function Proc_RemoveClient(Name$)
For T.NewClient=Each NewClient
If T\Name$=Name$
CloseTCPStream T\TCPStream
Delete T : Delay 2000
EndIf
Next
End Function
Client Code :
-------------
Global Window_Width=600
Global Window_Height=215
Global Window_Left=410
Global Window_Top=400
Global Window_Title$="Filax window"
; Declaration d'une fenetre et des boutons
; ----------------------------------------
Global Filax_Window=CreateWindow(Window_Title$,Window_Left,Window_Top,Window_Width,Window_Height,0,1+8)
Global Filax_Bouton01=CreateButton("&Connection au serveur",10,10,130,30,Filax_Window)
Global Filax_Bouton02=CreateButton("&Déconnection du serveur",10,40,130,30,Filax_Window)
Global Filax_Bouton03=CreateButton("&Envoyer une phrase",10,70,130,30,Filax_Window)
Global Filax_Liste01=CreateListBox( 150,10,430,150,Filax_Window )
Global ClientMode=0
Global ServerMode=0
Global ClientName$="Filax"
While Not KeyHit(1)
; ----------------------------
; Boucle de gestion des gadget
; ----------------------------
Select WaitEvent(0)
Case $401
Select EventSource()
Case Filax_Bouton01
If ClientMode=0 Then
ClientStream=OpenTCPStream("localhost",8080)
If ClientStream<>0 Then
WriteString ClientStream,ClientName$
InsertGadgetItem Filax_Liste01,0,"Connection au serveur ok ..." : WaitEvent(0)
ClientMode=1
Else
InsertGadgetItem Filax_Liste01,0,"Connection du serveur impossible ..." : WaitEvent(0)
ClientMode=0
End If
EndIf
Case Filax_Bouton02
If ClientMode=1 Then
WriteString ClientStream,"[DISCONNECT]"
WriteString ClientStream,ClientName$
Delay 2000
CloseTCPStream(ClientStream)
InsertGadgetItem Filax_Liste01,0,"Déconnection du serveur ok ..." : WaitEvent(0)
ClientMode=0
EndIf
Case Filax_Bouton03
Delay 1000
End Select
Case $803
End
End Select
Wend