コード例 #1
0
 private void Setup(int portNr)
 {
     try
     {
         server = new CEthernetServer <ConnectionBase>(Name, "0.0.0.0", portNr, "TCP", clientBuffeSize, 0);
         log.Info($"{Name} started on port {portNr}");
     }
     catch
     {
         log.Error($"The name:{Name} does not occur in the RGOSerice list in the configuration ");
     }
     AllServers.Add(this);
 }
コード例 #2
0
        static void Main(string[] args)
        {
            Encoding Enc    = Encoding.ASCII;
            string   reply  = "This is the reply form the server";
            var      Server = new CEthernetServer <ConnectionBase>("MyServ", "127.0.0.1", 16669, "TCP", 512, 10);

            Server.ReportError = (p, n) => Console.WriteLine($"Error: {p}, on: {n}");

            Server.NewConnection = connection =>
            {
                Console.WriteLine($"A new client connected: {connection}");
                connection.ConnStats.ConnectionTimeout = 5;

                connection.ProcessDataAction = () =>
                {
                    var text = Enc.GetString(connection.IncomingData);
                    Console.WriteLine($"Incoming data({Server.NrConnections}): {text.Substring(0, connection.NrReceivedBytes)}");
                    connection.SendDataAsync(Enc.GetBytes(reply), reply.Length);
                };
            };

            Console.ReadLine();
        }