예제 #1
0
 internal void SendMessage(string message, TcpClient client)
 {
     try {
         var encodedMessage = ServerUtility.EncodeMessageAsBytes(message);
         if (Verbose)
         {
             Logger.Info($"Sent [{ServerUtility.EncodeMessage(message)}] to client {Clients[client]}", "INFO-VERBOSE");
         }
         StreamUtil.Write(client.GetStream(), encodedMessage);
     } catch (IOException) {
         Logger.Warn($"Client {Clients[client]} disconnected!");
         faultyClients.Add(client);
     }
 }
예제 #2
0
 private void EmitMessage(string message, bool skipEncoding = false)
 {
     try {
         var outBytes = ServerUtility.EncodeMessageAsBytes(message, skipEncoding);
         lastHeartbeatTime = DateTime.Now;
         if (verbose)
         {
             Debug.Log($"Sent message: {ServerUtility.EncodeMessage(message, skipEncoding)}");
         }
         StreamUtil.Write(client.GetStream(), outBytes);
     } catch (Exception e) {
         panelWrapper.AddOutput(e.Message);
         //for quicker testing, we reconnect if something goes wrong.
         client.Close();
         ConnectToServer();
     }
 }