Example #1
0
 private async Task WorkWith(TcpClient client)
 {
     var connection = new Connection(client); 
     clientBase.TryAdd(client, connection);
     while (true)
     {
         Message message = await connection.ReadMessage();
         if (message.Text.StartsWith("/c "))
         {
             string done = await ElCapitano.MakeCommand(message.Text.Substring(3));
             Message raport = new Message();
             raport.Text = done;
             await connection.SendMessage(raport);
         }
         else
         {
             foreach (Connection con in clientBase.Values)
             {
                 try
                 {
                     await con.SendMessage(message);
                 }
                 catch (Exception ex) { Console.WriteLine("POLUNDRA!!!: {0}", ex); }
             }
         }
     }
 }
Example #2
0
 public async Task SendMessage(Message dove)
 {
     var ms = new MemoryStream();
     ms.SetLength(4);
     ms.Position = 4;
     ProtoBuf.Serializer.Serialize(ms, dove);
     int length = (int)ms.Length - 4;
     WriteInt32BigEndian(length, ms.GetBuffer(), 0);
     ms.Position = 0;
     await ms.CopyToAsync(stream);
 }