Modify

#2906 closed Bug (Duplicate)

TCPRecv can't detect closed client web browser sockets

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: 3.3.13.16 Severity: None
Keywords: TCPRecv Cc:

Description

Last time I checked beta versions error detection was improved but still can't detect a client's web browser closed connection and must rely on other means to close the socket.

This problem has been well documented in a ticket that is now closed, but i'm hoping that somebody will consider re-opening it to solve the last remaining problem.

The last test I ran was on beta version 3.3.13.16 and the issue was still there. Last known working example is version 3.3.8.1.

https://www.autoitscript.com/trac/autoit/ticket/2596

Attachments (0)

Change History (12)

comment:1 by Jpm, on Oct 14, 2014 at 1:36:35 PM

Can you point/attached repro script which illustrate what you want to be solved?

comment:2 by anonymous, on Oct 16, 2014 at 4:54:36 AM

This is the example that should show that web page sockets are not being closed when client closed their web browser where 3.3.8.1 had no problems in detecting the closed socket.

Start this script then use your web browser to navigate to 127.0.0.1:81, wait for the connection, then after the established connection, close the browser. 3.3.8.1 will detect the closed browser where further versions fail and must rely on alternate means to close the socket.

Thanks.

TCPStartup()
$serversock = TCPListen('127.0.0.1', 81)
If @error Then Exit ; we know this one.
While 1
	Do
		$hi = TCPAccept($serversock)
		If @error Then Exit ; we know this one.
	Until $hi <> -1
	MsgBox(0,"Connected","A client has connected...")

	$ti = TimerInit()

	While 1
		TCPRecv($hi,1500)
		If @error Then
			MsgBox(0,"Closed","Closing the connection: " & @error)
			TCPCloseSocket($hi)
			ExitLoop
		EndIf

		#cs ; alternate means for closing inactive sockets
		If TimerDiff($ti) > 99 Then
			TCPSend($hi, 'data')
			If @error Then MsgBox(0,"SEND ERROR!",@error)
			$ti = TimerInit()
		EndIf
		#ce
	WEnd
WEnd

comment:3 by anonymous, on Oct 16, 2014 at 4:58:30 AM

If the previous script was not any help here is another example. The same principle applies here. Navigate to 127.0.0.1:81, wait for connection then close the browser.

#include <Date.au3>


$socket = -1
TCPStartup()
$srvsck = TCPListen("127.0.0.1",80)
If @error Then Exit
While 1
	If $socket = -1 Then
		Do
			$socket = TCPAccept($srvsck)
			If $socket <> -1 Then MsgBox(1,"Test","Connection was made")
		Until $socket <> -1
	EndIf
	$rcvmsg = TCPRecv($socket,1000)
	If Not @error And $rcvmsg <> "" Then
		$P = "sending data"
		$size = StringLen($P)
		$cachehtml = ""
		$sendwebhdrs = ""
		$webstatsval = "HTTP/1.1 200 OK"
		$webheadrval = "Cache-Control: " & $cachehtml
		$webtrafdate = "Date: " & _NowCalc()
		$webcontents = "Content-Type: text/html"
		$webbodylens = "Content-Length: " & $size
		$webpersisst = "";"Connection: close"
		If $webstatsval <> "" Then $sendwebhdrs &= $webstatsval & @CRLF
		If $webheadrval <> "" Then $sendwebhdrs &= $webheadrval & @CRLF
		If $webtrafdate <> "" Then $sendwebhdrs &= $webtrafdate & @CRLF
		If $webcontents <> "" Then $sendwebhdrs &= $webcontents & @CRLF
		If $webpersisst <> "" Then $sendwebhdrs &= $webpersisst & @CRLF
		If $webbodylens <> "" Then $sendwebhdrs &= $webbodylens & @CRLF
		TCPSend($socket,$sendwebhdrs & @CRLF & $P)
		MsgBox(1,"goal",$rcvmsg)
	ElseIf @error Then
		MsgBox(1,"close",$socket & @CRLF & @error)
		TCPCloseSocket($socket)
		$socket = -1
	EndIf
WEnd

in reply to:  2 comment:4 by anonymous, on Oct 16, 2014 at 5:01:28 AM

Sorry this script was likely to showcase the @error problems which have since been fixed, see next example... Sorry about that.

comment:5 by Jpm, on Oct 16, 2014 at 9:11:46 AM

I assume next example = comment #3

in reply to:  5 comment:6 by anonymous, on Oct 18, 2014 at 8:55:23 AM

Replying to Jpm:

I assume next example = comment #3

Yeah sorry about that.
Comment 3 is has been my test script for seeing if future version can detect a closed client side web browser socket.
Previous comment no long applies since @errors have since been fixed, thanks.

comment:7 by anonymous, on Oct 18, 2014 at 8:59:40 AM

Looks like i aslo messed up in this scrip and the port is now 80...

So you would have to navigate your web broswser to 127.0.0.1 istead of 127.0.0.1:81.
Sorry about that.... geeze. i swear i'm not trying to mess up.

comment:8 by matwachich, on Aug 25, 2015 at 12:01:25 AM

Same problem with AutoIt v3.3.14.0 and beta3.3.15.0
This really needs to be fixed

Thanks

comment:9 by FIX_TCP, on Jun 5, 2016 at 12:19:35 AM

Autit version 3.3.8 proves again to be a more reliable version when it comes to TCP functions. I was working with Autoit v3.3.14.0 for windows 10, when suddenly TCPsend started doing very strange things. It refused to send the entire picture and would always leave 1 bit left unsent. Rendering my server script useless for media content. I did all the common things a person might do to fix the problem and my final solution was to downgrade back to 3.3.8.

Thanks again for all your hard work created and maintaining Autoit3.

comment:10 by Jpm, on Jun 7, 2016 at 2:03:23 PM

Can you post a script showing the regresssion between 3.3.14.0 and 3.3.8?
Thanks for your cooperation

comment:11 by anonymous, on Jun 30, 2016 at 4:42:41 PM

I will have to write a compressed server that can respond to an html request with pictures on it. I'm not sure if I have the time or desire to complete that task. The server I was using is larger than it needs to be for a useful example. Good luck and I understand if you do not wish to pursue this without proper documentations.

comment:12 by Jpm, on Jul 25, 2020 at 9:36:34 AM

Resolution: Duplicate
Status: newclosed

wait #2596 closing

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.