Exemplo n.º 1
0
 public void ConnectionsShouldNotExceedMaxLength()
 {
     this._relay = new WebSocketRelay(Guid.NewGuid(), "My Relay", 5);
     for (int i = 0; i < 10; i++)
     {
         this._relay.Add(new WebSocketConnection(null, null, null, null, null));
         if (i >= 5)
         {
             Assert.That(this._relay.Count == 5);
         }
     }
 }
Exemplo n.º 2
0
        static void testRelay()
        {
            FleckLog.Level = LogLevel.Debug;
            var relay  = new WebSocketRelay();
            var server = new WebSocketServer("ws://0.0.0.0:8181");

            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    Console.WriteLine("Open!");
                    relay.Add(socket);
                    socket.Send("Echo: You have Joined the Group [" + relay.Name + "]");
                    relay.Broadcast("Relay: " + socket.ConnectionInfo.Id.ToString() + " Joined", socket.ConnectionInfo.Id);
                };
                socket.OnClose = () =>
                {
                    Console.WriteLine("Close!");
                    relay.Remove(socket);
                    relay.Broadcast("Relay [" + socket.ConnectionInfo.Id.ToString() + "]: " + socket.ConnectionInfo.Id.ToString() + " Left", socket.ConnectionInfo.Id);
                };
                socket.OnMessage = message =>
                {
                    Console.WriteLine(message);
                    socket.Send("Echo: " + message);
                    relay.Broadcast("Relay [" + socket.ConnectionInfo.Id.ToString() + "]: " + message, socket.ConnectionInfo.Id);
                };
            });

            var input = Console.ReadLine();

            while (input != "exit")
            {
                foreach (var socket in relay.ToList())
                {
                    socket.Send(input);
                }
                input = Console.ReadLine();
            }
        }
Exemplo n.º 3
0
 public void Setup()
 {
     this._relay = new WebSocketRelay();
 }