Exemplo n.º 1
0
        private void btConnect_Click(object sender, EventArgs e)
        {
            string text  = tbIpEndPoint.Text;
            var    parts = text.Split(':');

            if (parts.Length != 2)
            {
                MessageBox.Show("Enter IP:port");
                return;
            }

            string ip      = parts[0];
            var    ipParts = ip.Split('.');

            if (ipParts.Length != 4)
            {
                MessageBox.Show("Ip is incorrect");
                return;
            }

            IPAddress ipResult;

            if (!IPAddress.TryParse(ip, out ipResult))
            {
                MessageBox.Show("One or more parts of ip is wrong!");
                return;
            }


            string port = parts[1];
            int    iPort;

            if (!int.TryParse(port, out iPort) || iPort <= 0 || iPort >= ushort.MaxValue)
            {
                MessageBox.Show("Port is incorrect");
            }

            IPEndPoint ipep = new IPEndPoint(ipResult, iPort);

            client = new ChatClient(ipep);
            client.Join();
            client.MessageReceived        += Cliet_MessagesReceived;
            client.PrivateMessageReceived += CLient_PrivateMessageReceived;
            client.OnGetUsersOnline       += GetUsers;
            JoinUI();
        }