﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
3572	TCPSend can hang forever without returning an error	ferbfletcher	Jpm	"See this forum post for additional information:
https://www.autoitscript.com/forum/topic/190989-tcpsend-in-loop-eventually-causes-program-not-responding/

When TCPSend is called in a loop, (without closing the socket and opening it each time), TCPSend seems to hang forever after a certain amount of data has been sent.  This seems to have no relationship to how fast or slow the data is sent, or how large the data is, other than the fact that if you send the data slower or at a lower amount of data, it will take longer to see the hang.

This was first discovered by sending data to a proprietary non-autoit 3rd-party tcp server, which I have no control over, and which I have no way to see how that server is configured.  However, the autoit server code included here causes the same client hang.

Please note that the server code included here is not the code in question, and is only included so that the client will run and hang.

Server Code, make sure this is running before starting the client code.  The server code and the client code can be ran on the same PC.

SERVER CODE:

{{{
TCPStartup()
$iListenSocket = TCPListen(""127.0.0.1"", 500, 100)

Do
  $iSocket = TCPAccept($iListenSocket)
Until $iSocket <> -1 ;if different from -1 a client is connected.

while 1
  $sReceived = TCPRecv($iSocket,100)
  sleep(10)
WEnd
}}}


CLIENT CODE:

{{{
TCPStartup()

$iSocket = TCPConnect(""127.0.0.1"", 500)
$x = 0
Local $mydata

;This is to make some data for testing purposes
For $a = 1 to 100
  $mydata &= ""xxxxxxxxxxxxxxxxxxxx""
Next

While 1
  $x += 1
  TCPSend($iSocket, $mydata)
  If @error <> 0 Then MsgBox(0,""Error"",@error)
  ToolTip($x) ;this is for a visual indication of program running
  Sleep(10)
WEnd
}}}

If it appears that I am sending an unrealistic amount of data at an unrealistic speed, that's true, but it shows the hang faster.  If you lower the data size and slow down the sending rate, the hang will still happen after the same amount of data has been sent but you will have to wait much longer for that amount of data to be sent.

The coding method may not be perfect, but the reason I am posting this as a bug is because TCPSend should NEVER hang forever.  If there is an issue, it should instead return an error.  However, there is no error returned, it just hangs.  That makes it appear to be a bug within TCPSend, where some sending issue is not properly being caught.  If caught, it could return an error and the program could deal with that error.
"	Bug	closed		AutoIt	3.3.14.2	None	Works For Me		
