internal static void connectCallback(IAsyncResult ar)
        {
            TcpClientSocketObject socketObj = (TcpClientSocketObject)ar.AsyncState;

            try {
                socketObj.socket.EndConnect(ar);

                socketObj.connectDone.Set();
            } catch (Exception) { }
        }
Example #2
0
        public int CreateSocket(IPEndPoint ipEP)
        {
            TcpClientSocketObject socketObj = new TcpClientSocketObject();

            socketObj.remoteIpEP  = ipEP;
            socketObj.DisplayName = GetDisplayName(ipEP);
            socketObj.Parent      = this;
            socketObj.Children    = null;
            socketObjs.Add(socketObj);

            //Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //socketObj.socket = socket;

            //Connect(socketObj);

            return(0);
        }
Example #3
0
        private void ShowTCPClientView()
        {
            TCPClientModel        p1 = (TCPClientModel)socketModels[status.index1];
            TcpClientSocketObject p2 = (TcpClientSocketObject)p1.Children[status.index2];

            TsocketStatus.Visibility = Visibility.Visible;
            if (p2.socket != null && p2.socket.Connected)
            {
                TsocketStatus.Text = "已连接";
            }
            else
            {
                TsocketStatus.Text = "未连接";
            }
            BTCConnect.Visibility = Visibility.Visible;
            BTCConnect.IsEnabled  = true;
            if (p2.socket != null && p2.socket.Connected)
            {
                BTCConnect.Content = "断开";
            }
            else
            {
                BTCConnect.Content = "连接";
            }

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

            TremoteIP.Text   = p2.remoteIpEP.Address.ToString();
            TremotePort.Text = p2.remoteIpEP.Port.ToString();
            if (p2.socket != null && p2.socket.Connected)
            {
                TlocalPort.Text = ((IPEndPoint)p2.socket.LocalEndPoint).Port.ToString();
            }
            else
            {
                TlocalPort.Text = "-1";
            }
        }
Example #4
0
        private void Connect(TcpClientSocketObject socketObj)
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socketObj.socket = socket;
            socketObj.connectDone.Reset();
            var ar = socketObj.socket.BeginConnect(socketObj.remoteIpEP, AsynchronousSocketListener.connectCallback, socketObj);

            try {
                if (socketObj.connectDone.WaitOne(400))
                {
                    if (socketObj.socket.Connected)
                    {
                        AsynchronousSocketListener.StartRead(socketObj);
                    }
                }
                else
                {
                    socketObj.socket.EndConnect(ar);
                }
            } catch (Exception) {
            }
        }
Example #5
0
        private void BTCConnect_Click(object sender, RoutedEventArgs e)
        {
            SocketModel p1 = (SocketModel)socketModels[status.index1];

            if (p1 is TCPServerSocket)
            {
                DelNode(status.index1, status.index2, status.index3);
            }
            else if (p1 is TCPClientModel)
            {
                TcpClientSocketObject p2 = (TcpClientSocketObject)p1.Children[status.index2];

                if (p2.socket != null && p2.socket.Connected)
                {
                    ((TCPClientModel)p1).Disconnect(status.index2);
                }
                else
                {
                    ((TCPClientModel)p1).Connect(status.index2);
                }
            }

            RefreshDisplay();
        }