コード例 #1
0
ファイル: Connection.cs プロジェクト: nicnicvv/SimpleChat
 protected void RemoveCommand(MessageProtocols protocol)
 {
     if (commands.ContainsKey(protocol))
     {
         commands.Remove(protocol);
     }
 }
コード例 #2
0
ファイル: Connection.cs プロジェクト: nicnicvv/SimpleChat
        public void Send(MessageProtocols protocol, object obj = null, bool encrypt = true)
        {
            if (writer == null || writer.BaseStream == null)
            {
                return;
            }

            string line = "";

            if (obj != null)
            {
                line = JsonConvert.SerializeObject(obj);
            }

            if (encrypt && cipher != null)
            {
                line = NetworkUtil.InsertEscape(cipher.Encrypt(protocol.ToString())) + "," + NetworkUtil.InsertEscape(cipher.Encrypt(line));
            }
            else
            {
                line = NetworkUtil.InsertEscape(protocol.ToString()) + "," + NetworkUtil.InsertEscape(line);
            }

            try
            {
                writer.WriteLine(line);
                writer.Flush();
            }
            catch (Exception) { }
        }
コード例 #3
0
 public void Broadcast(MessageProtocols protocol, Worker worker, object obj)
 {
     lock (workersLock)
         foreach (Worker w in workers)
         {
             if (worker == null || worker != w)
             {
                 w.Send(protocol, obj);
             }
         }
 }
コード例 #4
0
 /// <summary>
 /// Sends a message to all connected clients except the given worker.
 /// </summary>
 /// <param name="message">The message to sent to the users</param>
 /// <param name="worker">The work that does not receive the message</param>
 public void Broadcast(MessageProtocols protocol, object obj)
 {
     Broadcast(protocol, null, obj);
 }
コード例 #5
0
ファイル: Connection.cs プロジェクト: nicnicvv/SimpleChat
 protected void AddCommand(MessageProtocols protocol, Action <NetworkMessage> func)
 {
     commands[protocol] = func;
 }