carloselectro Posted November 17, 2015 Share Posted November 17, 2015 (edited) I am connecting to a server with TCP and I can never get the same response from the server with TCPRecv.I know for sure my commands are fine because it's sending me the right response with another software (Hercules).I am including the response I should get from the server.(It's about 180 lines)TCPRecv returns only a couple of lines and sometime many. I can never get everything.Here is part of my code: Func Receive_data() Opt("TCPTimeout", 100) ;100 milliseconds TCPStartup() Local $szIPADDRESS = "192.168.11.36" Local $nPORT = 5038 $ConnectedSocket = -1 $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT) ; If there is an error... show it and exit If @error Then MsgBox(4112, "Error", "Connect error: " & @error) Exit EndIf ;Sending data TCPSend($ConnectedSocket,"Action: PJSIPShowEndpoint" & @CRLF)) TCPSend($ConnectedSocket,"ActionID: 1" & @CRLF) TCPSend($ConnectedSocket,"Endpoint: U_8374" & @CRLF & @CRLF) ;Receiving data Do $response = TCPRecv($ConnectedSocket, 2048) Until $response <> "" ConsoleWrite("Data received: " & $response) TCPShutdown() Exit EndFunc ;==>Receive_data Any help will be greatly appreciated. Right_Response.txt Edited November 17, 2015 by carloselectro Link to comment Share on other sites More sharing options...
JohnOne Posted November 17, 2015 Share Posted November 17, 2015 Try$response = "" Do $response &= TCPRecv($ConnectedSocket, 2048) Until @error 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...
carloselectro Posted November 17, 2015 Author Share Posted November 17, 2015 (edited) I have just tried, and it's not returning anything. It loops endlessly.The best I got so far is with this code:But I only get part of the data. Do $response &= TCPRecv($ConnectedSocket, 2048) Until StringRegExp($response,@CRLF & @CRLF) Edited November 17, 2015 by carloselectro Link to comment Share on other sites More sharing options...
carloselectro Posted November 18, 2015 Author Share Posted November 18, 2015 I finally got it with this regex:I match everything between the first string with the last string. local $response = "" Do $response &= TCPRecv($ConnectedSocket, 2048) Until StringRegExp($response, '(?s)Response(.*)ListItems') ConsoleWrite("Data received: " & $response & @CRLF) Link to comment Share on other sites More sharing options...
ripdad Posted November 18, 2015 Share Posted November 18, 2015 expandcollapse popupFunc Receive_data() TCPStartup() Local $szIPADDRESS = "192.168.11.36" Local $nPORT = "5038" Local $Socket = TCPConnect($szIPADDRESS, $nPORT) Local $error = @error If $error Then; If there is an error... show it and exit MsgBox(4112, "Error", "Connect error: " & $error) Exit EndIf ;Sending data Local $str = "" $str &= "Action: PJSIPShowEndpoint" & @CRLF $str &= "ActionID: 1" & @CRLF $str &= "Endpoint: U_8374" & @CRLF & @CRLF TCPSend($Socket, $str) $error = @error If $error Then; If there is an error... show it and exit MsgBox(4112, "Error", "Send error: " & $error) Exit EndIf Local $sRecv, $sData = "" ;Receiving data For $i = 1 To 200 $sRecv = TCPRecv($Socket, 2048) If @error Then ExitLoop ElseIf StringLen($sRecv) Then $sData &= $sRecv $i = 0 EndIf Sleep(10) Next ConsoleWrite("Data received:" & @CRLF & $sData & @CRLF) TCPCloseSocket($Socket) TCPShutDown() EndFunc "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward 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