C
C#2y ago
Ang619

❔ my socket changes his connected attribute to false right after i sucessfully received data :(

Hello community, i am writing a chatroom application, where i wrote a Task to receive messages. However, after i sucessfully received the first data, the socket changes his connected attribute to false, and my application stops. I wonder why this happens, and i also dont understand why i dont get thrown into the Catch block, and instead the application closes. The connected attribute changes to false immediately after the receiveAsync is sucessfully executed, at the begining of the Task. On the second round of the while loop, my application closes at the receiveAsync line. The Task is some lines, so i uploaded the code here: https://codeshare.io/6pZjop I appreciate any help.
7 Replies
Buddy
Buddy2y ago
Don't use Connected property. Please implement something like a heartbeat instead as Connected property is the state of the last operation
Ang619
Ang619OP2y ago
I just wonder if that would help me? Because once the socket changes his attribute to connected = false, i cant receive any more messages. A heartbear would be cool to check if users are indeed still online, but i dont think that helps with my problem :/ Right now the server simply removes a client, when it cant send a message to him because the socket is not connected anymore or similar. I already checked if the server removes the client, but thats not the case. I dont get why the socket suddenly disconnects at the client side.
Buddy
Buddy2y ago
Remove the connected property and see again, If you still receieve messages
Ang619
Ang619OP2y ago
Unfortunatly not..
Buddy
Buddy2y ago
Do you have it set to keep alive? Socket option
Ang619
Ang619OP2y ago
Gotta try that. Ty Unfortunetly that didnt help, i am still trying to solve this somehow
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server