Modify

Opened 10 years ago

Closed 4 years ago

Last modified 2 years ago

#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 Changed 10 years ago by Jpm

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

comment:2 follow-up: Changed 10 years ago by anonymous

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 Changed 10 years ago by anonymous

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

comment:4 in reply to: ↑ 2 Changed 10 years ago by anonymous

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

comment:5 follow-up: Changed 10 years ago by Jpm

I assume next example = comment #3

comment:6 in reply to: ↑ 5 Changed 10 years ago by anonymous

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 Changed 10 years ago by anonymous

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 Changed 9 years ago by matwachich

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

Thanks

comment:9 Changed 8 years ago by FIX_TCP

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 Changed 8 years ago by Jpm

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

comment:11 Changed 8 years ago by anonymous

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 Changed 4 years ago by Jpm

  • Resolution set to Duplicate
  • Status changed from new to closed

wait #2596 closing

Last edited 2 years ago by Jpm (previous) (diff)

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.