Esempio n. 1
0
        public override async Task Start()
        {
            try
            {
                if (Working)
                {
                    return;
                }
                hostName = new HostName(IpAddress);
                Socket   = new StreamSocket();
                Socket.Control.KeepAlive = false;

                Debug.WriteLine("Connecting to:" + hostName.DisplayName);

                await Socket.ConnectAsync(hostName, RemoteServiceName);

                OnStartSucess?.Invoke();
                Debug.WriteLine("Connected");
                Working = true;
            }
            catch (Exception e)
            {
                if (SocketError.GetStatus(e.HResult) == SocketErrorStatus.Unknown)
                {
                }
                Debug.WriteLine(string.Format("Received data: \"{0}\"",
                                              "Read stream failed with error: " + e.Message));
                OnStartFailed?.Invoke(e);
                Dispose();
            }
        }
Esempio n. 2
0
        public override async Task Start()
        {
            try
            {
                if (Working)
                {
                    return;
                }
                IsServer      = true;
                ClientSockets = new List <StreamSocket>();
                Listener      = new StreamSocketListener()
                {
                    Control = { KeepAlive = false }
                };
                Listener.ConnectionReceived += OnConnection;
                var hostname = new HostName(IpAddress);
                await Listener.BindEndpointAsync(hostname, RemoteServiceName);

                Working = true;
                OnStartSucess?.Invoke();
            }
            catch (Exception e)
            {
                OnStartFailed?.Invoke(e);
            }
        }