示例#1
0
 public void OnGreenButtonClicked()
 {
     if (server != null)
     {
         server.Accept();
     }
 }
示例#2
0
        public void ItWorks()
        {
            var network_key = new byte[] {
                0xd4, 0xa1, 0xcb, 0x88, 0xa6, 0x6f, 0x02, 0xf8, 0xdb, 0x63, 0x5c,
                0xe2, 0x64, 0x41, 0xcc, 0x5d, 0xac, 0x1b, 0x08, 0x42, 0x0c, 0xea,
                0xac, 0x23, 0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb
            };

            var client_keypair = PublicKeyAuth.GenerateKeyPair();
            var server_keypair = PublicKeyAuth.GenerateKeyPair();

            var client = new Client(network_key, server_keypair.PublicKey, client_keypair);
            var server = new Server(network_key, server_keypair);

            // Client -> Server [1]
            var client_hello = client.Hello();

            server.AcceptHello(client_hello);

            // Client <- Server [2]
            var server_hello = server.Hello();

            client.AcceptHello(server_hello);

            Assert.True(
                Enumerable.SequenceEqual(client.EphemeralDerivedSecret, server.EphemeralDerivedSecret),
                "The ephemeral derived secrets are not the same" +
                "client: " +
                $"{string.Join(" ", client.EphemeralDerivedSecret.Select(x => x.ToString()).ToArray())}\n" +
                "server: " +
                $"{string.Join(" ", server.EphemeralDerivedSecret.Select(x => x.ToString()).ToArray())}"
                );
            Assert.True(
                Enumerable.SequenceEqual(client.ServerDerivedSecret, server.ServerDerivedSecret),
                "The Server derived secrets are not the same\n" +
                "client: " +
                $"{string.Join(" ", client.ServerDerivedSecret.Select(x => x.ToString()).ToArray())}\n" +
                "server: " +
                $"{string.Join(" ", server.ServerDerivedSecret.Select(x => x.ToString()).ToArray())}"
                );

            // Client -> Server [3]
            var client_auth = client.Authenticate();

            server.AcceptAuth(client_auth);

            Assert.True(
                Enumerable.SequenceEqual(client.ClientDerivedSecret, server.ClientDerivedSecret),
                "The Client derived secrets are not the same\n" +
                "client: " +
                $"{string.Join(" ", client.ClientDerivedSecret.Select(x => x.ToString()).ToArray())}\n" +
                "server: " +
                $"{string.Join(" ", server.ClientDerivedSecret.Select(x => x.ToString()).ToArray())}"
                );

            // Client <- Server [4]
            var server_accept = server.Accept();

            client.VerifyAccept(server_accept);
        }
示例#3
0
 public virtual SecureSocket AcceptSocket(AsyncCallback callback)
 {
     if (Server == null)
     {
         throw new InvalidOperationException();
     }
     return((SecureSocket)Server.Accept(callback));
 }
示例#4
0
 /// <summary>
 /// Accepts a pending connection request.
 /// </summary>
 /// <returns>A <see cref="SecureSocket"/> used to send and receive data.</returns>
 /// <exception cref="InvalidOperationException">The listener has not been started with a call to Start.</exception>
 /// <exception cref="SocketException">An operating system error occurs while accessing the SecureSocket.</exception>
 /// <exception cref="SecurityException">Unable to create the SSPI credentials.</exception>
 /// <remarks>AcceptSocket returns a SecureSocket that you can use to send and receive data. This SecureSocket is initialized with the IP address and port number of the remote machine. You can use any of the Send and Receive methods available in the Socket class to communicate with the remote machine.<br><b>Note</b>   When you finish using the Socket, be sure to call its Close method.</br><br><b>Note</b>   If your application is relatively simple, consider using the AcceptTcpClient method rather than AcceptSocket. SecureTcpClient provides you with simple methods for sending and receiving data over a network.</br></remarks>
 public virtual SecureSocket AcceptSocket(ISocketMonitor monitor = null)
 {
     if (Server == null)
     {
         throw new InvalidOperationException();
     }
     return((SecureSocket)Server.Accept(monitor));
 }
 public void WaitForConnection()
 {
     Console.WriteLine("Waiting for a connection...");
     // Program is suspended while waiting for an incoming connection.
     Connection = Server.Accept();
     OnConnect?.Invoke();
     Console.WriteLine("Connection accepted!");
 }
示例#6
0
        /// <summary>
        /// Creates a new socket for a connection.
        /// </summary>
        /// <returns>A socket.</returns>
        public Socket AcceptSocket()
        {
            if (!Active)
            {
                throw new InvalidOperationException("Not listening. You must call the Start() method before calling this method.");
            }

            return(Server.Accept());
        }
示例#7
0
        protected void DoAccept(RCRunner runner, RCClosure closure, RCLong left, RCLong right)
        {
            RCBot bot = runner.GetBot(closure.Bot);

            for (int i = 0; i < left.Count; ++i)
            {
                Server server = (Server)bot.Get(left[i]);
                server.Accept(runner, closure, right[0]);
            }
        }
 private void Ser()
 {
     ser = new Server();
     //接続イベント
     ser.OnConnectEvent += (tcpClient) => { Debug.Log(tcpClient.Client.RemoteEndPoint); };
     //データ受信時イベント
     ser.receiveCallBack += (jsonBytes) =>
     {    //ここに処理を記入
         Debug.Log(Encoding.Default.GetString(jsonBytes));
     };
     //受信要求待ち
     ser.Accept();
 }
        static void Main(string[] args)
        {
            Server server     = new Server(500, "DEPO Storm 1420K4", "Коммутационный сервер", "Intel® C242", "Intel® Xeon® E-2100/2200", 920, 3, 10);
            Cable  cable1     = new Cable(50, 1, 5);
            Cable  cable2     = new Cable(30, 2, 3);
            Cable  cable3     = new Cable(20, 3, 2);
            Cable  extraCable = new Cable(20, 3, 2);

            server.Add(cable1);
            server.Add(cable2);
            server.Add(cable3);
            server.Add(extraCable);
            Workstation workstation1     = new Workstation(100, 1);
            Workstation workstation2     = new Workstation(100, 2);
            Workstation workstation3     = new Workstation(100, 3);
            Workstation workstation4     = new Workstation(100, 4);
            Workstation workstation5     = new Workstation(100, 5);
            Workstation extraWorkstation = new Workstation(100, 500);

            cable1.Add(workstation1);
            cable1.Add(workstation2);
            cable1.Add(workstation3);
            cable1.Add(workstation4);
            cable1.Add(workstation5);
            cable1.Add(extraWorkstation);
            Workstation workstation6 = new Workstation(150, 6);
            Workstation workstation7 = new Workstation(150, 7);
            Workstation workstation8 = new Workstation(150, 8);

            cable2.Add(workstation6);
            cable2.Add(workstation7);
            cable2.Add(workstation8);
            Workstation workstation9  = new Workstation(200, 9);
            Workstation workstation10 = new Workstation(200, 10);

            cable3.Add(workstation9);
            cable3.Add(workstation10);

            EstimateVisitor visitor = new EstimateVisitor();

            server.Accept(visitor);
            Console.WriteLine($"Estimate of network per month: {visitor.m_estimate}");
            Console.ReadKey();
        }
        public async void ItWorks()
        {
            var network_key = new byte[] {
                0xd4, 0xa1, 0xcb, 0x88, 0xa6, 0x6f, 0x02, 0xf8, 0xdb, 0x63, 0x5c,
                0xe2, 0x64, 0x41, 0xcc, 0x5d, 0xac, 0x1b, 0x08, 0x42, 0x0c, 0xea,
                0xac, 0x23, 0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb
            };

            var client_keypair = PublicKeyAuth.GenerateKeyPair();
            var server_keypair = PublicKeyAuth.GenerateKeyPair();

            var client = new Client(network_key, server_keypair.PublicKey, client_keypair);
            var server = new Server(network_key, server_keypair);

            // Client -> Server [1]
            var client_hello = client.Hello();

            server.AcceptHello(client_hello);

            // Client <- Server [2]
            var server_hello = server.Hello();

            client.AcceptHello(server_hello);

            // Client -> Server [3]
            var client_auth = client.Authenticate();

            server.AcceptAuth(client_auth);

            // Client <- Server [4]
            var server_accept = server.Accept();

            client.VerifyAccept(server_accept);

            var a = client.ClientEphemeralPubKey;
            var b = client.ServerEphemeralPubKey;

            var(client_boxer, client_unboxer) = BoxStreamBuilder.Build(
                client.ClientDerivedSecret,
                server_keypair.PublicKey,
                client_keypair.PublicKey,
                network_key,
                a, b
                );

            var(server_boxer, server_unboxer) = BoxStreamBuilder.Build(
                server.ClientDerivedSecret,
                client_keypair.PublicKey,
                server_keypair.PublicKey,
                network_key,
                a, b
                );

            var plain = System.Text.Encoding.Unicode.GetBytes("hello world");

            var msg = client_boxer.Box(plain);

            using (var stream = StreamFromBytes(msg))
            {
                var decoded = await server_unboxer.Unbox(stream);

                Assert.Equal(plain, decoded);
            }
        }