private void HandleClose() { // handle a "close" request from the client // get the sessionId that the client just asked us to close var closedSessionId = ulong.Parse(reader.ReadLine()); Console.WriteLine($"[{clientThread.ManagedThreadId.ToString()}] Client asked to close session id {closedSessionId}"); try { // close the session in the session table sessionTable.CloseSession(closedSessionId); // send closed message back to client SendClosed(closedSessionId); // record that this client no longer has an open session if (sessionId == closedSessionId) { Console.WriteLine($"[{clientThread.ManagedThreadId.ToString()}] Client no longer has an open session"); sessionId = 0; } } catch (SessionException se) { SendError(se.Message); } catch (Exception ex) { SendError(ex.Message); } }
private void HandleClose() { // handle a "close" request from the client // get the sessionId that the client just asked us to close string line = reader.ReadLine(); ulong closeThis = ulong.Parse(line); try { // Make sure client has requested to close their own sessionId, and not someone else's if (sessionId != 0 && closeThis != sessionId) { throw new SessionException("Hey! you're trying to close the wrong session Id!"); } // close the session in the session table sessionTable.CloseSession(closeThis); // send closed message back to client SendClosed(closeThis); // record that this client no longer has an open session sessionId = 0; } catch (SessionException se) { SendError(se.Message); } catch (Exception ex) { SendError(ex.Message); } }