Exemplo n.º 1
0
        public void SendAllActionBool()
        {
            ushort port = TestHelper.GetPort();

            using var server = new EasyTcpServer().Start(port);;

            using var client = new EasyTcpClient();
            Assert.IsTrue(client.Connect(IPAddress.Any, port));

            server.SendAllAction(0, true);
            server.SendAllAction("ECHO", true);
        }
Exemplo n.º 2
0
        public void SendAllArray()
        {
            ushort port = TestHelper.GetPort();

            using var server = new EasyTcpServer().Start(port);

            using var client = new EasyTcpClient();
            Assert.IsTrue(client.Connect(IPAddress.Any, port));

            byte[] data = new byte[100];
            server.SendAllAction(0, data);
            server.SendAllAction("ECHO", data);
        }
Exemplo n.º 3
0
        public void SendAllActionString()
        {
            ushort port = TestHelper.GetPort();

            using var server = new EasyTcpServer().Start(port);

            using var client = new EasyTcpClient();
            Assert.IsTrue(client.Connect(IPAddress.Any, port));

            string data = "Data";

            server.SendAllAction(0, data);
            server.SendAllAction(0, data, Encoding.UTF32);      //Send with different encoding
            server.SendAllAction("ECHO", data);
            server.SendAllAction("ECHO", data, Encoding.UTF32); //Send with different encoding
        }
Exemplo n.º 4
0
        public void SendAllActionInt()
        {
            ushort port   = TestHelper.GetPort();
            var    server = new EasyTcpServer();

            server.Start(port);

            var client = new EasyTcpClient();

            Assert.IsTrue(client.Connect(IPAddress.Any, port));

            int data = 123;

            server.SendAllAction(0, data);
            server.SendAllAction("ECHO", data);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Send action (uint) to connected clients
 /// </summary>
 /// <param name="server"></param>
 /// <param name="action">action code as string</param>
 /// <param name="data">data to send to connected clients</param>
 public static void SendAllAction(this EasyTcpServer server, string action, uint data) =>
 server.SendAllAction(action.ToActionCode(), BitConverter.GetBytes(data));
Exemplo n.º 6
0
 /// <summary>
 /// Send action (uint) to connected clients
 /// </summary>
 /// <param name="server"></param>
 /// <param name="action">action code</param>
 /// <param name="data">data to send to connected clients</param>
 public static void SendAllAction(this EasyTcpServer server, int action, uint data) =>
 server.SendAllAction(action, BitConverter.GetBytes(data));
Exemplo n.º 7
0
 /// <summary>
 /// Send action (byte[]) to connected clients
 /// </summary>
 /// <param name="server"></param>
 /// <param name="action">action code as string</param>
 /// <param name="data">data to send to connected clients</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 public static void SendAllAction(this EasyTcpServer server, string action, byte[] data = null,
                                  bool compression = false)
 => server.SendAllAction(action.ToActionCode(), data, compression);
Exemplo n.º 8
0
 /// <summary>
 /// Send action (object) to connected clients
 /// </summary>
 /// <param name="server"></param>
 /// <param name="action">action code as string</param>
 /// <param name="data">data to send to connected clients</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 public static void SendAllAction(this EasyTcpServer server, string action, object data, bool compression = false)
 => server.SendAllAction(action.ToActionCode(), server?.Serialize(data), compression);
Exemplo n.º 9
0
 /// <summary>
 /// Send action (IEasyTcpPacket) to connected clients
 /// </summary>
 /// <param name="server"></param>
 /// <param name="action">action code as string</param>
 /// <param name="data">data to send to connected clients</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 public static void SendAllAction(this EasyTcpServer server, string action, IEasyTcpPacket data, bool compression = false)
 => server.SendAllAction(action.ToActionCode(), data.Data, compression);
Exemplo n.º 10
0
 /// <summary>
 /// Send action (IEasyTcpPacket) to connected clients
 /// </summary>
 /// <param name="server"></param>
 /// <param name="action">action code</param>
 /// <param name="data">data to send to connected clients</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 public static void SendAllAction(this EasyTcpServer server, int action, IEasyTcpPacket data, bool compression = false)
 => server.SendAllAction(action, data.Data, compression);
Exemplo n.º 11
0
 /// <summary>
 /// Send action (string) to connected clients
 /// </summary>
 /// <param name="server"></param>
 /// <param name="action">action code as string</param>
 /// <param name="data">data to send to connected clients</param>
 /// <param name="encoding">encoding type (Default: UTF8)</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 public static void SendAllAction(this EasyTcpServer server, string action, string data,
                                  Encoding encoding = null, bool compression = false)
 => server.SendAllAction(action.ToActionCode(), (encoding ?? Encoding.UTF8).GetBytes(data), compression);