Exemplo n.º 1
0
        private void ShowTCPServerView()
        {
            TCPServerSocket       p1 = (TCPServerSocket)socketModels[status.index1];
            TcpServerSocketObject p2 = (TcpServerSocketObject)p1.Children[status.index2];

            TsocketStatus.Visibility = Visibility.Visible;
            TLlocalPort.Visibility   = Visibility.Visible;
            TlocalPort.Visibility    = Visibility.Visible;
            if (status.index3 == -1)
            {
                BTSStartListen.Visibility = Visibility.Visible;
                TsocketStatus.Text        = p2.IsListening ? "正在监听" : "未监听";
                BTSStartListen.Content    = p2.IsListening ? "停止监听" : "启动监听";

                TlocalPort.Text = ((IPEndPoint)p2.socket.LocalEndPoint).Port.ToString();
            }
            else
            {
                RemoteSocketObject p3 = (RemoteSocketObject)p2.Children[status.index3];

                BTCConnect.Visibility = Visibility.Visible;
                TsocketStatus.Text    = p3.socket.Connected ? "已连接" : "未连接";
                BTCConnect.Content    = "断开连接";
                BTCConnect.IsEnabled  = p3.socket.Connected;

                TLremoteIP.Visibility   = Visibility.Visible;
                TremoteIP.Visibility    = Visibility.Visible;
                TLremotePort.Visibility = Visibility.Visible;
                TremotePort.Visibility  = Visibility.Visible;

                TremoteIP.Text   = ((IPEndPoint)p3.socket.RemoteEndPoint).Address.ToString();
                TremotePort.Text = ((IPEndPoint)p3.socket.RemoteEndPoint).Port.ToString();
                TlocalPort.Text  = ((IPEndPoint)p3.socket.LocalEndPoint).Port.ToString();
            }
        }
Exemplo n.º 2
0
        private void BTSStartListen_Click(object sender, RoutedEventArgs e)
        {
            TCPServerSocket p1 = socketModels[status.index1] as TCPServerSocket;

            if (p1 == null || status.index2 < 0)
            {
                return;
            }

            TcpServerSocketObject p2 = (TcpServerSocketObject)p1.Children[status.index2];

            if (p2.IsListening)
            {
                p1.StopListening(status.index2);
            }
            else
            {
                p1.StartListening(status.index2);
            }
            RefreshDisplay();
        }