ApplicationServer.TrackingServer.Forward C# (CSharp) Method

Forward() public method

public Forward ( ) : void
return void
    public void Forward()
    {
      int oldConnection = Server.Connections.Count;
      while (true)
      {
        if (oldConnection < Server.Connections.Count)
          Console.WriteLine("New client connected");
        else if (oldConnection > Server.Connections.Count)
          Console.WriteLine("Client Disconnected");
        oldConnection = Server.Connections.Count;
        NetIncomingMessage message = this.Server.ReadMessage();

        if (message != null)
        {
          switch (message.MessageType)
          {
            case NetIncomingMessageType.Data:
              NetOutgoingMessage sendMessage = this.Server.CreateMessage();
              sendMessage.Write(message);
              for (int i = 0; i < Server.Connections.Count; i++)
              {
                if (message.SenderConnection != Server.Connections[i])
                {
                  this.Server.SendToAll(sendMessage, message.DeliveryMethod);
                  //Console.WriteLine("Message forwarded");
                }
              }
              break;
            default:
              break;
          }
        }
        else
        {
        }
        //System.Threading.Thread.Sleep((int)(1f / 30f * 1000));
      }
    }

Usage Example

Example #1
0
 public static void Main(string[] args)
 {
   try
   {
     Console.WriteLine("Insert server name");
     string name = Console.ReadLine();
     Console.WriteLine("Insert port");
     int port = System.Convert.ToInt32(Console.ReadLine());
     TrackingServer server = new TrackingServer(port, name);
     server.Server.Start();
     server.Forward();
   }
   catch (Exception e)
   {
     Console.WriteLine(e.Message);
   }
 }