Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var nowcfSettings = new NoWCFSettings()
            {
                //FindEncryptionCertificateSubjectName = "MyCustomCertificate",
                BasicCommunicationEncryptionKey = "jshgntjh43t",
            }.InitializeEncryption();

            var server = new NoWCFServer(8866, nowcfSettings);

            server.HandleException          = (e) => Console.WriteLine(e);
            server.HandleClientException    = (cl, e) => Console.WriteLine($"{cl.RemoteEndPoint}; {e}");
            server.OnClientConnectionClosed = (cl) => Console.WriteLine($"{cl.RemoteEndPoint}; CLOSED");
            server.AddDuplexProtocol <ServerProtocolA, ClientInvokeProtocol>();
            server.AddProtocol <ServerProtocolB>();
            while (true)
            {
                Console.WriteLine("Starting server..");
                server.Start();
                Console.WriteLine("Server started.");
                Console.ReadKey();
                Console.WriteLine("Stopping server..");
                server.Stop();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Server Mode
        /// </summary>
        public NoWCFClient(Socket socket, NoWCFSettings settings) : base(settings)
        {
            _socket        = socket;
            _networkStream = new NetworkStream(socket, false);
            RemoteEndPoint = _socket.RemoteEndPoint;

            Console.WriteLine($"Connected ({RemoteEndPoint})");
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var nowcfSettings = new NoWCFSettings()
            {
                //FindEncryptionCertificateSubjectName = "MyCustomCertificate",
                BasicCommunicationEncryptionKey = "jshgntjh43t",
            }.InitializeEncryption();


            Console.Write("Number of connections to spawn: ");
            var connCnt = int.Parse(Console.ReadLine());

            Console.WriteLine();

            for (int i = 0; i < connCnt; ++i)
            {
                new Thread(() =>
                {
                    while (true)
                    {
                        var client                = new NoWCFClient(nowcfSettings);
                        client.HandleException    = (e) => Console.WriteLine($"{client.RemoteEndPoint}; {e}");
                        client.OnConnectionClosed = () => Console.WriteLine($"{client.RemoteEndPoint}; CLOSED");

                        try
                        {
                            client.Connect("127.0.0.1", 8866);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);

                            Thread.Sleep(1000);
                            continue;
                        }

                        client.RegisterDuplexProtocol <ClientProtocol, ServerInvokeProtocolA>();
                        client.RegisterInvokeProtocol <ServerInvokeProtocolB>();
                        client.BeginReceive();

                        while (true)
                        {
                            client.GetProtocol <ClientProtocol, ServerInvokeProtocolA>()?.CSOp1(rand.Next(0, 999999), 8);
                            client.GetProtocol <ServerInvokeProtocolB>()?.TEST("HAHAHA");
                            client.GetProtocol <ClientProtocol, ServerInvokeProtocolA>()?.CSOpt2(new List <TestClasss>()
                            {
                                new TestClasss()
                                {
                                    Member2 = 255,
                                    Member  = new List <TestClass2>()
                                    {
                                        { new TestClass2()
                                          {
                                              Mem = 669
                                          } },
                                        { new TestClass2()
                                          {
                                              Mem = 670
                                          } }
                                    }
                                },
                                new TestClasss()
                                {
                                    Member2 = 255,
                                    Member  = new List <TestClass2>()
                                    {
                                        { new TestClass2()
                                          {
                                              Mem = 669
                                          } },
                                        { new TestClass2()
                                          {
                                              Mem = 670
                                          } }
                                    }
                                }
                            });
                            Console.WriteLine($"ServerInvokeProtocolA.CSOp4(): {client.GetProtocol<ClientProtocol, ServerInvokeProtocolA>()?.CSOp4(rand.Next(0, 10000))}");
                            try
                            {
                                client.GetProtocol <ClientProtocol, ServerInvokeProtocolA>().CSSomeExceptionMethod();
                            }
                            catch (Exception ex) { Console.WriteLine(ex.Message); }

                            Thread.Sleep(750);

                            if (rand.Next(0, 10) == 0 || !client.Connected)
                            {
                                break;
                            }
                        }

                        client.Disconnect();
                    }
                }).Start();
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Client Mode
 /// </summary>
 public NoWCFClient(NoWCFSettings settings = null) : base(RandomString.Next(16), settings)
 {
 }