Пример #1
0
        private void btnConnecTest_Click(object sender, EventArgs e)
        {
            bool          socketFlag = false;
            bool          msgFlag    = false;
            SocketConnect mySocket   = new SocketConnect();

            if (tbxServerIp.Text != null && tbxServerPort != null)
            {
                mySocket   = new SocketConnect(tbxServerIp.Text, int.Parse(tbxServerPort.Text));
                socketFlag = true;
            }
            if (socketFlag)
            {
                mySocket.initSocketIpConnect();
            }
            if (tbxClientSend.Text != null)
            {
                msgFlag = true;
            }
            if (msgFlag)
            {
                mySocket.sentData(tbxClientSend.Text);
                tbxChatClient.Text += "Client:" + tbxClientSend.Text + "\r\n";
            }
        }
Пример #2
0
        private void clientListenServer()
        {
            bool          socketFlag = false;
            bool          fileFlag   = false;
            SocketConnect mySocket   = new SocketConnect();

            if (tbxServerIp.Text != null && tbxServerPort.Text != null && tbxClientIp.Text != null && tbxClientPort != null)
            {
                mySocket   = new SocketConnect(tbxServerIp.Text, int.Parse(tbxServerPort.Text), tbxClientIp.Text, int.Parse(tbxClientPort.Text));
                socketFlag = true;
            }

            if (socketFlag)
            {
                mySocket.initSocketIpConnect();
            }

            while (true)
            {
                try
                {
                    string chatStr = mySocket.listenStr();
                    tbxChatClient.Text += "Server:" + chatStr + "\r\n";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
                finally
                {
                }
            }
        }
Пример #3
0
        void clientRecvFile()
        {
            bool          socketFlag = false;
            bool          fileFlag   = false;
            SocketConnect mySocket   = new SocketConnect();

            if (tbxServerIp.Text != null && tbxServerPort.Text != null && tbxClientIp.Text != null && tbxClientPort != null && tbxServerMsgPort.Text != null && tbxClientMsgPort.Text != null)
            {
                mySocket   = new SocketConnect(tbxServerIp.Text, int.Parse(tbxServerMsgPort.Text), tbxClientIp.Text, int.Parse(tbxClientMsgPort.Text));
                socketFlag = true;
            }

            if (socketFlag)
            {
                mySocket.initSocketIpConnect();
            }

            while (true)
            {
                try
                {
                    string fileMsg = mySocket.recvFile();
                    tbxChatClient.Text += "成功接收文件\r\n";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
                finally
                {
                }
            }
        }