Ejemplo n.º 1
0
        void OnResolveCompletion(PPError result)
        {
            if (result != PPError.Ok)
            {
                PostMessage("Resolve failed.");
                return;
            }

            var addr = PPBHostResolver.GetNetAddress(resolver_, 0);

            PostMessage($"Resolved: {(Var)PPBNetAddress.DescribeAsString(addr, PPBool.True)}");

            var callback = new CompletionCallback(OnConnectCompletion);

            if (IsUDP)
            {
                PostMessage("Binding ...");
                remote_host_ = new PPResource(addr);
                var ipv4_addr = new PPNetAddressIPv4(0);
                PPBUDPSocket.Bind(udp_socket_, addr, callback);
            }
            else
            {
                PostMessage("Connecting ...");
                PPBTCPSocket.Connect(tcp_socket_, addr, callback);
            }
        }
Ejemplo n.º 2
0
        private void OnAcceptCompletion(PPError result, PPResource socket)
        {
            if (result != PPError.Ok)
            {
                instance.PostMessage($"server: Accept failed: {result}");
                return;
            }

            var addr = PPBTCPSocket.GetLocalAddress(socket);

            instance.PostMessage($"server: New connection from: {((Var)PPBNetAddress.DescribeAsString(addr, PPBool.True)).ToString()}");
            incomingSocket = new PPResource(socket);

            TryRead();
        }
Ejemplo n.º 3
0
        private void OnListenCompletion(PPError result)
        {
            var status = string.Empty;

            if (result != PPError.Ok)
            {
                instance.PostMessage($"server: Listen failed with: {result}");
                return;
            }

            var addr = PPBTCPSocket.GetLocalAddress(listeningSocket);

            instance.PostMessage($"server: Listening on: {((Var)PPBNetAddress.DescribeAsString(addr, PPBool.True)).AsString()}");

            TryAccept();
        }
Ejemplo n.º 4
0
        private void OnConnectCompletion(PPError result)
        {
            if (result != PPError.Ok)
            {
                var status = $"Connection failed: {result}";
                PostMessage(status);
                return;
            }

            if (IsUDP)
            {
                var addr = PPBUDPSocket.GetBoundAddress(udp_socket_);
                PostMessage($"Bound to: {((Var)PPBNetAddress.DescribeAsString(addr, PPBool.True)).AsString()}");
            }
            else
            {
                PostMessage("Connected");
            }

            Receive();
        }