コード例 #1
0
        private void ListedButton_Click(object sender, EventArgs e)
        {
            string ip    = this.IPContent.Text.Trim();
            string portS = this.ProtContent.Text.Trim();

            if (string.IsNullOrWhiteSpace(ip) || string.IsNullOrWhiteSpace(portS))
            {
                MessageBox.Show("请输入端口和Ip", "提示");
                return;
            }
            else
            {
                SocketError socketError = Request.Connect(ip, int.Parse(portS));
                if (socketError == SocketError.Success)
                {
                    this.ListedButton.Enabled = false;
                    this.GetMsgList.Items.Add("已连接到主机 " + ip + ":" + portS);
                    Request.OnReceiveData  += Request_OnReceiveData;
                    Request.OnServerClosed += Request_OnServerClosed;
                    Request.StartHeartbeat();
                    bool isSent = Request.Send(Overall.HeardPackage);
                    Task.Factory.StartNew(() =>
                    {
                        TimeSetting.Start();
                    });
                }
            }
        }