mcwwi/lib-rcon

Tcpclient not stopped when server is shutdown

Closed this issue · 2 comments

The tcpclient is still showing as being connected even if you stop the server not sure if this is a bug in the lib or just a tcpclient limitation.

Edit: Seems like tcpclients dont receive a disconnect https://stackoverflow.com/questions/15067014/c-sharp-detecting-tcp-disconnect so you would have to poll it

Edit: Code to check if the connection is still alive

if (cli.Client.Poll(0, SelectMode.SelectRead))
{
    byte[] buff = new byte[1];
    if (cli.Client.Receive(buff, SocketFlags.Peek) == 0)
        return false; // Connection is closed
}
return true; // Connection is open

They don't receive disconnects, but I can attempt to read and if 0 length is returned its usually due to closed connection (especially if its async read). I've seen the above code :)

I also use some sort of keep alive/poll in the application using list commands against the server - and reset the whole thing if it fails.

I see - if the mc server is closed down while connected to rcon .. this is a known issue. I'm thinking about re-working the code to use async rather than my own thread handling. I'll look at this as well tonight.