jvds Posted July 12, 2014 Share Posted July 12, 2014 hi, any one see my problem? i think i have a problem in the for to next loop but i cant quite get it right expandcollapse popup#include <Array.au3> HotKeySet("{F11}", "display") TCPStartup() $Main_Socket = TCPListen(@IPAddress1,999) If $Main_Socket = -1 then exit Local $Channel_Socket[1][2] $Channel_Socket[0][0]= -1 $Channel_Socket[0][1]= "" While 1 $Channel_Socket = Incoming_Connections($Main_Socket) ConsoleWrite ('+'&@LF) sleep(1000) WEnd Func Incoming_Connections($Main_Socket) ;~ ConsoleWrite ('UBound($Channel_Socket,0)= '&UBound($Channel_Socket,0)&@lf) ConsoleWrite ('UBound($Channel_Socket,1)= '&UBound($Channel_Socket,1)&@lf) ;~ ConsoleWrite ('UBound($Channel_Socket,2)= '&UBound($Channel_Socket,2)&@lf) For $sotket=0 to UBound($Channel_Socket,1)-1 ConsoleWrite ('$Channel_Socket['&$sotket&'][0]='&$Channel_Socket[$sotket][0]&@LF) ConsoleWrite ('$Channel_Socket['&$sotket&'][1]='&$Channel_Socket[$sotket][1]&@LF) ;~ _ArrayDisplay($Channel_Socket,"") If $Channel_Socket[$sotket][0] = -1 Then $Channel_Socket[$sotket][0] = TCPAccept($Main_Socket) if $Channel_Socket[$sotket][0] <> -1 then $Channel_Socket[$sotket][1] = Timerinit() ConsoleWrite('+New Conection Detected'&@lf) _ArrayAdd($Channel_Socket,-1&'|') EndIf Else _ReadChannel_Socket($sotket) EndIf Next Return $Channel_Socket EndFunc Func _ReadChannel_Socket($sotket) $datex = TCPRecv($Channel_Socket[$sotket][0],500) If $datex <> "" then consolewrite ('!$datex='&$datex&@LF) EndFunc Func display() _ArrayDisplay($Channel_Socket,"") EndFunc if i send data like the examble below, i only get the test1, and if i add more TCPsends, the last tcpsend does not get to the tcp reader func TCPStartup() $sokete = TCPConnect('192.168.1.4',999) if $sokete = -1 Then Exit SLEEP(1000) TCPSend($sokete,"test1") SLEEP(1000) TCPSend($sokete,"test2") any help appreciated Link to comment Share on other sites More sharing options...
Developers Jos Posted July 12, 2014 Developers Share Posted July 12, 2014 Try this as client: OnAutoItExitRegister("OnAutoItExit") ; TCPStartup() ; $sokete = TCPConnect(@IPAddress1,999) if $sokete = -1 Then Exit SLEEP(1000) TCPSend($sokete,"test1") SLEEP(1000) TCPSend($sokete,"test2") ; TCPCloseSocket($sokete) ; Func OnAutoItExit() TCPShutdown() ; Close the TCP service. EndFunc ;==>OnAutoItExit Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
jvds Posted July 12, 2014 Author Share Posted July 12, 2014 closing the socket works but there is something wrong in the loop or the first script, if i will hold the connection open and i send something it does not arrive instantly, its stays where ever is stays until a next packet arrives and then i get the first packet Link to comment Share on other sites More sharing options...
Developers Jos Posted July 12, 2014 Developers Share Posted July 12, 2014 You have a sleep(1000) in your main loop that shouldn't be there. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
jvds Posted July 12, 2014 Author Share Posted July 12, 2014 i was looping with a 1 sec sleep to test out, but it seems to work without the sleep, but if spamming f5 key on the second script there is still are a very low chance that it still does not arrive, if I have multiple connections on the script it may delay the packets more than a second if for example I send a large file on one of the connections, so i think it its not reliable i already tried the same with a 1D array, but the problem is the same, i want to store a timer on each connection, that is why i am trying with an 2d array The data does not get lost, it gets stuck in some kind of buffer or something until a next packet arrives and the new packet is stuck, and the older packet then gets kicked out and piked up, any idea why? Link to comment Share on other sites More sharing options...
Developers Jos Posted July 12, 2014 Developers Share Posted July 12, 2014 You are running in a single thread so only so much can be handled. Maybe you should shell a new instance of your script for each connection that is started. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
jvds Posted July 12, 2014 Author Share Posted July 12, 2014 thanks, I will look in to that, any tips on where to start? or what functions to look at for running multiple instances? I have never done it, and didn't know you can D= Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now