Sign in to follow this  
Followers 0
Radiance

TCPRecv won't set @error

3 posts in this topic

Hi all,

I'm running some TCP Server/Client scripts and having trouble determinating whether a client has already disconnected or not.

Please try the following two scripts (server first).

Server:

TCPStartup()
Opt("TCPTimeout", 0)

Global $gi_MainSocket = TCPListen(@IPAddress1, 4466)

While 1
    $gi_UserSocket = TCPAccept($gi_MainSocket)
    If $gi_UserSocket = -1 Then ContinueLoop

    While 1
        TCPRecv($gi_UserSocket, 2000)
        If @error AND @error <> -1 Then
            MsgBox(0, "", "Socket error!")
            TCPShutdown()
            Exit
        EndIf
    WEnd

WEnd

 

Client:

TCPStartup()
$iSock = TCPConnect(@IPAddress1, 4466)
;~ TCPCloseSocket($iSock)
TCPShutdown()

 

When running the client after the server has started, it will almost instantly end and the server gets an @error from the TCPRecv() func - you'll see the MsgBox.

Now add line 3 to the client script and run it again.

Even though the client has exited, the TCPRecv() still won't return an @error, the server can't see that the client is long gone.

Share this post


Link to post
Share on other sites



I haven't found a proper solution yet.

Looking at the open connections via netstat reveals that the server still has one in the state FIN_WAIT_2, waiting for an ACK from the client which he obviously never gets.

What really bugs me is that I have times where I can't even reproduce the obove case and everything works just as intendet.

I also can't spot why it sometimes works and sometimes it doesn't.

My only workaround is to set a timer in the server and let my clients send a heartbeat every few seconds.

If there's no heartbeat for a specified amount of time the server assumes that the client is no longer online and kills the socket.

 

Might this be a bug in AutoIts TCP engine?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

 

"why would you change" I don't know why, this topic was for that specific problem

 

I remember that they try to play around with @extended for some reason but i don't know the end result of it.

 

edit: ouh and the ticket concerning that topic

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

and its last 2 comments are really interesting

 

Have a nice read  :)

as far as i understand its fixed in beta i think... read topic links, test beta, is my best advice

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.

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0