protected static void DisconnectCallback(IAsyncResult ar) { RatClient context = (RatClient)ar.AsyncState; try { context.socket.EndDisconnect(ar); } catch (SocketException e) { // not sure } context.OnStateChanged(false, "Successfully disconnected from server"); }
protected static void AcceptCallback(IAsyncResult ar) { RatServer context = (RatServer)ar.AsyncState; try { Socket connection = context.socket.EndAccept(ar); RatClient client = new RatClient(connection); context.OnClientConnected(client); } catch (SocketException e) { } context.socket.BeginAccept(new AsyncCallback(AcceptCallback), context); }
protected static void ConnectCallback(IAsyncResult ar) { RatClient context = (RatClient)ar.AsyncState; try { context.socket.EndConnect(ar); if (context.socket.Connected) { context.OnStateChanged(true, "Successfully connected to server"); } } catch (SocketException e) { context.OnStateChanged(false, "Failed to connect to server: " + e.Message); } }
protected void OnClientConnected(RatClient client) { ClientConnected?.Invoke(this, client); }