/// <summary> /// Send a message by writing on the socket. /// </summary> /// <param name="msg"></param> public void send(CSMessage msg) { try { formatter.Serialize(tcpclient.GetStream(), msg); } catch (Exception e) { log(Severiry.ERROR, "Sending -> " + e.Message); } }
/// <summary> /// Process run method. /// </summary> /// <param name="token"></param> public void run(CancellationToken token) { while (tcpclient.Connected && !token.IsCancellationRequested) { try { CSMessage msg = (CSMessage)formatter.Deserialize(tcpclient.GetStream()); switch (msg.Type) { case MessageType.DECONNECTION: deconnetion(); break; case MessageType.LOGIN: loginHandler(this, msg); break; case MessageType.CHALLENGING: challengerHandler(this, msg); break; case MessageType.STOP_GAME: stopGameHandler(this, msg); break; case MessageType.END_GAME: endGameHandler(this, msg); break; default: handleMessage(msg); break; } } catch (Exception) { if (!token.IsCancellationRequested) { deconnetion(); } } } }
public abstract void handleMessage(CSMessage msg);