Radiance Posted February 24, 2015 Share Posted February 24, 2015 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. Link to comment Share on other sites More sharing options...
Radiance Posted February 26, 2015 Author Share Posted February 26, 2015 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? Link to comment Share on other sites More sharing options...
bogQ Posted February 26, 2015 Share Posted February 26, 2015 (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 topichttps://www.autoitscript.com/trac/autoit/ticket/2596and 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 February 26, 2015 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. Link to comment Share on other sites More sharing options...
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