Beispiel #1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if ((string.IsNullOrEmpty(textBox1.Text)) || (string.IsNullOrEmpty(textBox2.Text)))
            {
                MessageBox.Show("Campo(s) vazio(s)", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                ClientSocket cs = new ClientSocket();
                cs.SendCredentials(textBox1.Text, textBox2.Text);

                if (cs.Connected())
                {
                    this.Hide();
                    var form2 = new Form2();
                    form2.Closed += (s, args) => this.Close();
                    form2.Show();
                }
                StaticClientSocket.Client = cs;
            }
        }
Beispiel #2
0
    /// <summary>
    /// 客户端心跳
    /// </summary>
    private void HeartBeatUpdate()
    {
        if (!isHeartBeat || !clientSocket.Connected())
        {
            return;
        }

        if (Time.time - lastSendHeartBeatTime > heartBeatInterval)
        {
            // 发送心跳包
            clientSocket.Send(new HeartBeatMsg());
            lastSendHeartBeatTime = Time.time;
            Debug.Log("Client HeartBeat");
        }

        if (Time.time - lastRecvHeartBeatTime > heartBeatInterval * 3)
        {
            Debug.Log("失去server连接!");
            clientSocket.Close();
        }
    }
Beispiel #3
0
 private void Start()
 {
     client.Connected();
 }