Hi there,
i'm wondering if theres a need to unregister events before recreating new ones.
in my test client, i can get disconnected.
By clicking on a button, I can reconnect.
it's calling the 'connect()' function which calls the _TCP_Client_Create function and Registers 3 events (Connect, Disconnect & Receive).
The problem is that the Connect Event is not triggered when I reconnect my client.
Do I have to unregister event in some way ?
Heres is my code (its just a client which purpose is testing my server) :
#include <TCP.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
GUICreate("Network Test - Client", 500, 200, -1, -1)
Global $GUI_Messages = GUICtrlCreateEdit("en attente d'une action", 120, 10, 370, 180, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY)
GUICtrlSetBkColor ($GUI_Messages, 0xffffff)
$GUI_Button_Send1 = GUICtrlCreateButton("Connect", 10, 10, 100, 30)
$GUI_Button_Send2 = GUICtrlCreateButton("Send2", 10, 50, 100, 30)
GUISetState()
Func Connect()
Global $hclient
ConsoleWrite("hclient avant TCP_Client_Create=" & $hclient & @CRLF)
Global $hClient = _TCP_Client_Create(@IPAddress1, 37601); Create the client. Which will connect to the local ip address on port 88
ConsoleWrite("hclient apres TCP_Client_Create=" & $hclient & @CRLF)
_TCP_RegisterEvent($hClient, $TCP_CONNECT, "Connected"); And func "Connected" will get called when the client is connected.
_TCP_RegisterEvent($hClient, $TCP_DISCONNECT, "Disconnected"); And "Disconnected" will get called when the server disconnects us, or when the connection is lost.
_TCP_RegisterEvent($hClient, $TCP_RECEIVE, "Received"); Function "Received" will get called when something is received
EndFunc
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $GUI_Button_Send1
Connect()
Case $msg = $GUI_Button_Send2
ConsoleWrite("envoi au serveur !" & @CRLF)
GUICtrlSetData($GUI_Messages, @CRLF & "Tentative d'identification", 1)
If Not TCPSend($hclient,"2569EA0F69A71DD56BD87750|#A01") Then GUICtrlSetData($GUI_Messages, @CRLF & "Echec de l'envoi - wsa error:" & @error, 1)
EndSelect
WEnd
Func Connected($hSocket, $iError); We registered this (you see?), When we're connected (or not) this function will be called.
ConsoleWrite("appel de la fonction 'connected()'" & @crlf)
If not $iError Then; If there is no error...
GUICtrlSetData($GUI_Messages, @CRLF & "Connected to Server", 1); ... we're connected.
Else; ,else...
GUICtrlSetData($GUI_Messages, @CRLF & "Could not Connect", 1); ... we aren't.
EndIf
EndFunc
Func Received($hSocket, $sReceived, $iError); And we also registered this! Our homemade do-it-yourself function gets called when something is received.
GUICtrlSetData($GUI_Messages, @CRLF & $sReceived, 1) ;(and we'll display it)
ConsoleWrite("appel de la fonction Received()" & @CRLF)
EndFunc
Func Disconnected($hSocket, $iError); Our disconnect function. Notice that all functions should have an $iError parameter.
GUICtrlSetData($GUI_Messages, @CRLF & "Connection Lost", 1)
EndFunc