Jump to content

Recommended Posts

Posted (edited)

Server script:

TCPStartup()
OnAutoItExitRegister("Quit")
HotKeySet("{END}","Quit")

Global $sIPAddress = "192.168.1.11"
Global $iPort = 8082

While 1
    $iListenSocket = TCPListen($sIPAddress,$iPort)
    ToolTip("Listening"&@CRLF&$iListenSocket,0,0)

    $iSocket = -1
    Do
        $iSocket = TCPAccept($iListenSocket)
    Until $iSocket <> -1
    ToolTip("Accepted"&@CRLF&$iSocket,0,0)

    TCPCloseSocket($iListenSocket)

    Local $sBuffer = "", $sReceived = ""
    Do
      $sReceived &= $sBuffer
      $sBuffer = TCPRecv($iSocket, 1024)
    Until $sBuffer = "" or @error

    MsgBox(0,@error,$sReceived)

WEnd

Func Quit()
    TCPShutdown()
    Exit
EndFunc

Client script:

TCPStartup()

Global $ServerIP = "[my_public_ip_here]"
;~ Global $serverIP = "192.168.1.11"
Global $iPort = 8082

$iSocket = TCPConnect($ServerIP,$iPort)
TCPSend($iSocket,"asdfghjkl")
TCPCloseSocket($iSocket)
TCPShutdown()

When the Client script uses my internal IP, the message "asdfghjkl" comes through with no issues. But when my Client script uses my public IP address, the MsgBox on the Server shows blank. (Port is forwarded correctly.)

I know the connection "works" as the Server script successfully idles until I run the Client, at which point the Server pops an empty message box.
This happens regardless of whether the client is running on the same PC, another local PC, or a remote PC.

Edit: Same issue present with the TCPRecv example from the help file.

Edited by Sunblood
Posted
2 hours ago, JockoDundee said:

Does your router support hairpin turnaround?

I'm not sure what that is, Google is not giving me helpful information. I use a Netgear R7000 with AdvancedTomato.

I was able to make some progress though: the Server will receive the full message only when the Client closes the TCP socket. It seems the client is caching parts of the TCP message and then sending it all at once when the connection is closed. Not really useful when needing to do two-way communication.

Posted

Hairpinning, aka NAT loopback, is the ability of a router to loopback when presented with a seemingly external IP address that is really locally resolved.

When you think about it, you can see why without hairpinning this is a problem.  You are addressing a packet with a subnet that is not found on the LAN, therefore the router takes it and routes it to the internet, instead of to a LAN server.

 

Code hard, but don’t hard code...

Posted (edited)

Or ask a friend to test client script on his comp from his internet address and make sure your port is free/opened/forwarded for server script to work.

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

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...