Sunblood Posted November 15, 2021 Posted November 15, 2021 (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 November 15, 2021 by Sunblood
JockoDundee Posted November 15, 2021 Posted November 15, 2021 Does your router support hairpin turnaround? Code hard, but don’t hard code...
Sunblood Posted November 15, 2021 Author Posted November 15, 2021 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.
JockoDundee Posted November 16, 2021 Posted November 16, 2021 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...
bogQ Posted November 16, 2021 Posted November 16, 2021 (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 November 16, 2021 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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.
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