Issue with Connect() immediately after Disconnect()
See original GitHub issueI am facing an issue when I’m Disconnect()
ing from a server and try to reconnect immediately.
The Server I’m connecting to sends a heartbeat every 5 seconds. If no heartbeat is received for more than 5 seconds (plus some grace period), I want to renew the connection by doing
client.Disconnect(); // because IsConnected is still true
client.Connect();
which gives me the following output
[SimpleTcp.Client] disconnecting from 127.0.0.1:8000
[SimpleTcp.Client] initializing client
[SimpleTcp.Client] connecting to 127.0.0.1:8000
Event Connected
[SimpleTcp.Client] data receiver canceled, peer disconnected
Event Disconnected, e.Reason: Normal
[SimpleTcp.Client] dispose complete
[SimpleTcp.Client] data receiver canceled, peer disconnected
Event Disconnected, e.Reason: Normal
[SimpleTcp.Client] dispose complete
This seems like a timing/synchronization problem.
I can work around it by putting a Thread.Sleep(500);
after the client.Disconnect();
, but that’s probably not the most reliable solution.
Is there a better way?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
TCP/IP: connecting immediately after disconnecting
I'm working on a client and server protocols over TCP/IP. It is completely asynchronous – that is it uses TcpClient 's methods ...
Read more >on('disconnect') handler called twice after `disconnect()` if ...
It looks like socket.connect() is causing the second disconnect handler to fire. Perhaps this is because if you call connect() immediately ...
Read more >Remote Desktop client disconnects and can't reconnect to ...
Troubleshooting an issue in which remote desktop client disconnects and can't reconnect to the same session.
Read more >Is there a way to reconnect a function after disconnecting it?
I'm trying to create a global cooldown where after I cast a magic ... Unequipped:Connect(function() activated:Disconnect() end) end act().
Read more >My scripts only work once. Help me using Disconnect()?
I have a lot of scripts in my game that use :connect(function()). After moving through my game, eventually these just stopped working. I...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @powerzone3000 could you try with v2.6.0.2? Please re-open if any issues.
NuGet: https://www.nuget.org/packages/SuperSimpleTcp/2.6.0.2 Commit: https://github.com/jchristn/SuperSimpleTcp/commit/66b3893f78f11953bc11c53917d232af6ad0fdb4
Thank you for your response @jchristn. Unfortunately, the behavior is still the same for me.