MTSC  1.0.5
Build TCP servers out of modules with handlers for communication, exception and logging.
BroadcastHandler.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Net.Sockets;
4 using System.Text;
5 
7 {
8  public class BroadcastHandler : IHandler
9  {
10  private List<string> buffer = new List<string>();
15  {
16 
17  }
18 
24  public void Broadcast(Client client, string message)
25  {
26  client.QueueMessage(UnicodeEncoding.Unicode.GetBytes(message));
27  }
28 
29  void IHandler.Disconnected(Client client)
30  {
31 
32  }
33 
34  bool IHandler.HandleReceivedMessage(Client client, Message message)
35  {
36  client.LogDebug("Broadcast: " + UnicodeEncoding.Unicode.GetString(message.MessageBytes));
37  client.Log(">" + UnicodeEncoding.Unicode.GetString(message.MessageBytes));
38  return false;
39  }
40 
41  bool IHandler.HandleSendMessage(Client client, ref Message message)
42  {
43  return false;
44  }
45 
46  bool IHandler.InitializeConnection(Client client)
47  {
48  return true;
49  }
50 
51  bool IHandler.PreHandleReceivedMessage(Client client, ref Message message)
52  {
53  return false;
54  }
55 
56  void IHandler.Tick(Client client)
57  {
58 
59  }
60  }
61 }
void Log(string log)
Logs the message onto the associated loggers.
Definition: Client.cs:67
void Broadcast(Client client, string message)
Broadcast a message to all other clients connected to the server.
BroadcastHandler()
Creates a new instance of BroadcastHandler.
void Disconnected(Client client)
Called when the client is disconnected.
void QueueMessage(byte[] message)
Add a message to the message queue.
Definition: Client.cs:59
Handler interface for client communication.
Definition: IHandler.cs:11
void LogDebug(string debugMessage)
Logs the debug message onto the associated loggers.
Definition: Client.cs:78
Base class for TCP Client.
Definition: Client.cs:19