Jump to content

Cannot get consistent data with TCPRecv???


Recommended Posts

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 by carloselectro
Link to comment
Share on other sites

Func 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...