Beispiel #1
0
        public async Task MainAsync()
        {
            await Task.CompletedTask;

            if (mutex.WaitOne(TimeSpan.Zero, true))
            {
                var socketToken = "{{SocketToken}}";

                var serviceCollection = new ServiceCollection()
                                        .AddLogging()
                                        .AddSingleton <Client.Client>();

                var serviceProvider = serviceCollection.BuildServiceProvider();

                serviceProvider
                .GetService <ILoggerFactory>()
                .AddConsole();

                _client                 = serviceProvider.GetService <Client.Client>();
                _client.OnConnected    += _client_OnConnected;
                _client.OnDisconnected += _client_OnDisconnected;
                _client.Connect(socketToken);
            }

            System.Console.ReadLine();
        }
Beispiel #2
0
        public static void pitch(string _ip)
        {
            Client.Client cl = new Client.Client(_ip, 5255, "jak", "kaj");
            cl.Connect();

            TestClass tcl1 = new TestClass(true);

            tcl1.b        = new double[] { 666.66, 777.777 };
            tcl1.inrr     = new Innerer(true);
            tcl1.a        = 871;
            tcl1.dsa._asd = "merge";

            List <ClassElement> al = new List <ClassElement> ();
            ClassParser         cp = new ClassParser();

            cp.Traverse(tcl1, "gigel");
            al = cp.ListOfFields;

            cl.List = al;
            bool b = cl.Send();

            if (!b)
            {
                Console.WriteLine("Nope");
            }
        }
        public void Client_ConnectMultipleClientsToServer_ConnectionsSucceed()
        {
            var port = Network.GetTcpPort();
            var uriString = string.Format("http://localhost:{0}", port);
            var uri = new Uri(uriString);

            var applicationContext = Substitute.For<IApplicationContext>();
            using (var server = new Server.Server(uri))
            {
                server.Start(applicationContext);

                var clients = new List<Client.Client>();
                const int NumClients = 100;
                var clientReceivedMessageCount = 0;
                for (var i = 0; i < NumClients; i++)
                {
                    var client = new Client.Client(uri);
                    client.OnMessage += (sender, eventArgs) => clientReceivedMessageCount++;
                    var connected = client.Connect(Client.Enums.TransportType.ServerSentEvents);
                    Assert.IsTrue(connected);
                    clients.Add(client);
                }
                Assert.AreEqual(NumClients, clients.Count);
                server.SendMessage("x");
                foreach (var client in clients)
                {
                    client.Dispose();
                }

                // Probably won't receive all messages - no sleep or synchronisation implemented to ensure exactly NumClients messages
                Assert.IsTrue(clientReceivedMessageCount > 0);
                Assert.IsTrue(clientReceivedMessageCount <= NumClients);
            }
        }
        public void Client_ConnectToServerThenTerminateServer_ConnectionSucceeds()
        {
            var port = Network.GetTcpPort();
            var uriString = string.Format("http://localhost:{0}", port);
            var uri = new Uri(uriString);

            var applicationContext = Substitute.For<IApplicationContext>();
            var server = new Server.Server(uri);
            server.Start(applicationContext);

            using (var client = new Client.Client(uri))
            {
                var connected = client.Connect(Client.Enums.TransportType.ServerSentEvents);
                Assert.IsTrue(connected);
                server.Dispose();
            }
        }
Beispiel #5
0
        public static void bat(string _ip)
        {
            Client.Client cl = new Client.Client(_ip, 5255, "jak", "kaj");
            cl.Connect();

            object tcl2 = new TestClass();
            bool   b    = cl.Get(ref tcl2, "gigel", typeof(TestClass));

            if (!b)
            {
                Console.WriteLine("Nope.");
            }

            Console.WriteLine(tcl2);
            Console.WriteLine("and should be : ");

            TestClass tcl1 = new TestClass(true);

            tcl1.b        = new double[] { 666.66, 777.777 };
            tcl1.inrr     = new Innerer(true);
            tcl1.a        = 871;
            tcl1.dsa._asd = "merge";
            Console.WriteLine(tcl1.ToString());
        }