Jump to content

Recommended Posts

Posted

I am trying networking with autoit and for one reason or the other, TCPRecv is not returning any responses. What am I doing wrong?

#cs
This script connects to google and retrieves the index page and echos it in a message box.
#ce

TCPStartup()
AutoItSetOption("TCPTimeout", 10000)

Global $ip, $conn, $recv
$ip = TCPNameToIP("google.com")
$port ="443"


If $ip == "" Then
    MsgBox(0, "TCPNameToIP", "Failed to get the ip address")
    Exit
EndIf

MsgBox(0, "IPAddress Of Google is ", $ip)

$conn = TCPConnect($ip, $port)
If @error Then
    MsgBox(0, "TCPConnect", "Connection To server failed. " & @CRLF & "Error : " & @error)
    Exit
EndIf

MsgBox(0, "TCPConnect", "Connected to " & $ip & " : "&$port)


TCPSend($conn, 'GET / HTTP/1.0' & @CRLF)
If @error Then
    MsgBox(0, "TCPSend", "Send To server failed. " & @CRLF & "Error : " & @error)
    Exit
EndIf

MsgBox(0, "TCPSend", "Data sent to " & $ip & " : "&$port)


$recv = TCPRecv($conn, 2000)

If @error Then
    MsgBox(0, "TCPSRecv", "Recv from server failed. " & @CRLF & "Error : " & @error)
    Exit
EndIf

MsgBox(0, "Data", $recv)

 

Posted

The google website is not a tcp server. If you want to download webpages, look into native function InetGet, or trancexx's WinHTTP functions, for example. If on the other hand, you wish to explore TCP, you could run two separate scripts, one running as TCP server, the other as receiver. There's plenty of examples of that on the forums (e.g., here, here, and here) .

BTW, it's considered bad practice to bump your owh thread within 24hrs.

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
  • Recently Browsing   0 members

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