79137913 Posted March 11, 2014 Share Posted March 11, 2014 HELLO!!! Well... I have this conection code: Func _Conectar(ByRef $sock, $sIP, $sPORT) ;Conecta un socket a un Ip y un Puerto. While TCPStartup() = 0 Sleep(10) WEnd While True $sock = TCPConnect($sIP, $sPORT) If $sock > 0 Then ExitLoop EndIf Sleep(1000) WEnd EndFunc ;==>_Conectar When the socket is conected to the server it will "talk". How i know if the server has closed the socket (serverside). I've tried with @Error on TCPRECV but it gives me -1 everytime TCPRECV = "" Is another way to know this? one without @error, something like IsSocketOpened($socket) THANKS FOR READING!!! Link to comment Share on other sites More sharing options...
FireFox Posted March 11, 2014 Share Posted March 11, 2014 Hi, Welcome to the AutoIt forum Please have a look at the helpfile examples. Br, FireFox. Link to comment Share on other sites More sharing options...
79137913 Posted March 11, 2014 Author Share Posted March 11, 2014 HELLO!!! Mr. FireFox... I already search in help files examplesbut i only found the @error technique. The TCP Functions are: Accept CloseSocket Connect IPtoName Recv Send Shutdown Startup Timeout No one of them helps me, because i have Blanks on the "chat" between This Client and the server, but the Connection still opened, i want to try reconect if the connection is closed by any side, no when a nullstring is recived (or nothing is recived). THANKS FOR READING!!! Link to comment Share on other sites More sharing options...
FireFox Posted March 11, 2014 Share Posted March 11, 2014 You didn't look how to correctly use those functions. e.g : While TCPStartup() = 0 Sleep(10) WEnd Is a huge no no. Link to comment Share on other sites More sharing options...
79137913 Posted March 11, 2014 Author Share Posted March 11, 2014 (edited) HELLO!!! That Part of the code is to wait until the server is listening. In others words, it will try to connect until it can make a connection with the server. Plz tell me whi i'm not using well that function? My bad... That part of code is to wait until the TCPStartup is Up and Running. The other part of the code that you didnt mentioned is to do what i Striked Through. THANKS FOR READING!!! Edited March 11, 2014 by 79137913 Link to comment Share on other sites More sharing options...
FireFox Posted March 11, 2014 Share Posted March 11, 2014 The start up of the TCP/UDP services should not fail (rare exceptions). Func _Conectar(ByRef $sock, $sIP, $sPORT) ;Conecta un socket a un Ip y un Puerto. TCPStartup() If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "TCPStartup(): Error code: " & $iError) Return False EndIf While True $sock = TCPConnect($sIP, $sPORT) If Not @error Then ExitLoop ;else retry connection Sleep(1000) WEnd EndFunc ;==>_Conectar Concerning the TCPRecv function, if an error is fired it means the connection is lost. Br, FireFox. Link to comment Share on other sites More sharing options...
79137913 Posted March 13, 2014 Author Share Posted March 13, 2014 (edited) HELLO!!! First of all Thank you. Now... Well, i've tried that but it didnt work. The conecction is ok, but when i: $Recibe = "" While $Recibe = "" $Recibe = TCPRecv($Socket,1000) $iError = @error If $iError Then MsgBox(0,"",$iError) EndIf Sleep(100) WEnd Every time the server sends information (when this code recieve something diferent of a nullstring) The error is 0 (no error). But when the server is silent (when this code do not recieve anything (recieve a nullstring)) the error is -1. I've checked: And there is no solution, as i see, because every one is getting a -1 when the buffer is empty and when the connection is down... so, we cant differentiate that. P.S: Plz, answer me THANKS FOR READING!!! Edited March 13, 2014 by 79137913 Link to comment Share on other sites More sharing options...
FireFox Posted March 13, 2014 Share Posted March 13, 2014 As I said, -1 means the connection is lost. It does not mean the server is not sending anything. You should check the script on server side, there's nothing you can fix here. Br, FireFox. Link to comment Share on other sites More sharing options...
79137913 Posted March 13, 2014 Author Share Posted March 13, 2014 (edited) HELLO!!! Mr. FireFox, Im sorry for my ignorance... How the connection could be lost if i can continue sending data to the au3 script after the error arrives In other words: 1) I connect to the server 2) I send a "Hello" String 3) The servers answers "Hello" 4) After i recieve the Hello on the Au3 Script and proceced it the next TCPRecv gives me an @error = -1 5) The error continues while nothing is recieved 6) The server sends a Petition for example "GiveMeData" 7) The au3 Script recieve the "GiveMeData" without problems and gives no error on this TCPRecv 8) The au3 Script answers "Im Script Number #" 9) Until i get another string from the server the au3 Script (TCPRecv) keeps giving @error = -1 So, if we use logic... at the 5 point the au3 script socket is down... but how can I recieve data on the 6th point ? THANKS FOR READING!!! Edited March 13, 2014 by 79137913 Link to comment Share on other sites More sharing options...
FireFox Posted March 13, 2014 Share Posted March 13, 2014 (edited) Yes you're right, I got this problem once and I did not remember it. I suggest you to ignore the error. Br, FireFox. Edited March 14, 2014 by FireFox Link to comment Share on other sites More sharing options...
FireFox Posted March 13, 2014 Share Posted March 13, 2014 (edited) And how to check if the connection : send a data (e.g : PING) and wait for its response (e.g : PONG). You may not have to wait for a response, as the TCP protocol checks for the packet to be successfully sent. Edited March 13, 2014 by FireFox Link to comment Share on other sites More sharing options...
79137913 Posted March 13, 2014 Author Share Posted March 13, 2014 (edited) HELLO!!! Great News Im not mad! BTW i cant Stress the server with a lot of "Pings" every 0.1 seconds form each client. I will put a directive to reconect every client when it dont recieve instructions in 15 minutes. Thank you very much! (the problem isnt solved but i have an answer) THANKS FOR READING!!! Edited March 13, 2014 by 79137913 Link to comment Share on other sites More sharing options...
FireFox Posted March 13, 2014 Share Posted March 13, 2014 Of course don't ping it everytime if not needed Link to comment Share on other sites More sharing options...
JohnOne Posted March 13, 2014 Share Posted March 13, 2014 If you try to TCPConnect on the port that is already open, you should get error indicating that the port is already in use. Meaning the connection is not lost. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
79137913 Posted March 17, 2014 Author Share Posted March 17, 2014 HELLO!!! John ... i've tried that and it didn't work, autoit connect every time i do a tcp Connect. Thank you, but the timeout option is the best for now. THANKS FOR READING!!! 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