WatsonTcpServer.ListClients() is empty if called "too early"
See original GitHub issueHey!
server.Start();
client.Connect();
Console.WriteLine(server.ListClients().Count());
await Task.Delay(1); // Thread.Sleep(1) also works
Console.WriteLine(server.ListClients().Count());
This will output:
0
1
This is very problematic as one might not expect server.ListClients()
to return an empty enumerable, especially if they’re not aware of this issue.
I’m not sure why a 1ms delay seems to fix it. Are some async events (registering the client on server side) not awaited/fired on time or something?
Why does this happen and could it be fixed?
Issue Analytics
- State:
- Created 10 months ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Issues · jchristn/WatsonTcp
WatsonTcp is the easiest way to build TCP-based clients and servers in C#. ... WatsonTcpServer.ListClients() is empty if called "too early" help wanted....
Read more >C# Socket keep receiving empty message
Reason for receiving empty messages is that your client socket remains connected. You can wait to receive more messages with your client, if...
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
Yeah, very understandable.
You can label this issue if you wish and keep it for later or whatever, I guess it’ll be fine for now. Especially if I’m the first one reporting about it.
In a real server<->client scenario, this probably won’t be important anyway because of the fact there is already ping between everything.
This was found because I ran some tests locally, but I can hardly think of a situation where you’d need to call
ListClients()
less than a few milliseconds after a client connects.Yeah, not sure how I’m going to be able to fix that. There’s very little code between the server accepting the connection and the client metadata being added to the client list. This is a biproduct of the fact that the client is returning faster from
BeginConnect()
(and everything else it does withinConnect()
than the server does from the first few steps ofAcceptConnections()
.