Exemplo n.º 1
0
        private void btnSendMsg_Click(object sender, EventArgs e)
        {
            bool          socketFlag = false;
            bool          msgFlag    = false;
            SocketConnect mySocket   = new SocketConnect();

            if (tbxServerIp.Text != null && tbxServerPort != null && tbxClientIp.Text != null && tbxClientPort != null)
            {
                mySocket   = new SocketConnect(tbxClientIp.Text, int.Parse(tbxClientPort.Text));
                socketFlag = true;
            }
            if (socketFlag)
            {
                mySocket.initSocketIpConnect();
            }
            if (tbxServerMsg.Text != null)
            {
                msgFlag = true;
            }
            if (msgFlag)
            {
                mySocket.sentData(tbxServerMsg.Text);
                tbxServerListenMsg.Text += "Server:" + tbxServerMsg.Text + "\r\n";
            }
        }
Exemplo n.º 2
0
        void listenClientMsg()
        {
            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);
             * }
             */
            while (true)
            {
                string listenMsg = mySocket.listenStr();
                tbxServerListenMsg.Text += "Client:" + listenMsg + "\r\n";
            }
        }
Exemplo n.º 3
0
        void serverSendFile()
        {
            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 (tbxFilePath.Text != null)
            {
                fileFlag = true;
            }
            if (fileFlag)
            {
                try
                {
                    mySocket.sendFile(tbxFilePath.Text);
                    tbxServerListenMsg.Text += "成功发送文件\r\n";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }