Jump to content

msizec

Members
  • Posts

    6
  • Joined

  • Last visited

msizec's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. Do you think is about my code ? About the fact the server and the client are on the same host ? or maybe your UDF ?
  2. I made more tests and now I can tell that the 'Connected' event is triggered some times, and nopt triggerd some other times. It even happens at the first connection. For my tests, the server and the client are on the same pc. When a client has connected to the server, the server send a little command. I thought maybe the server was sending it to fast for the client to register his 3 events, but the problem is still here even with a sleep in the server's code. However there is no problem with the "reveived" and "connected" events. They're always triggered. Can you help me a bit kip plz ? Thx
  3. I still have the same problem. Once the 'Connected' event triggered a first time, and if the client disconnects for a reason, any other call of the Connect function will not trigger the 'Connected' event again.
  4. Up ?
  5. 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
  6. Hi Kip and First : Great job to you and others contributors. i'm trying to use your UDF in a client/Server oriented update program. I would like to know if there's is a way to prevent an already connected client to reconnects the server. At this time, theres no protection. I could implement an IP-based protection with an 2D array filled during every call of the Connected() func with the socket and its IP but I don't like the fact to maintain another array. is there a way to add the socket's IP to the TCP_SOCKETS array in your udf. That way i could get it when I call TCP_Server_ClientList(). Thanks for your remarks
×
×
  • Create New...