コード例 #1
0
        private void ThreadExecute(object data)
        {
            SocketClientSync client = (SocketClientSync)data;
            string           read   = null;

            while (client.Connected)
            {
                read = client.Read(500);

                if (client.LastException != null)
                {
                    if (!(client.LastException is TimeoutException))
                    {
                        UpdateList("Read Error! " + client.LastException.Message);
                        client.Disconnect();
                    }
                }
                else
                {
                    if (read != null)
                    {
                        CheckMsg(read);
                    }
                }

                Thread.Sleep(11);
            }
        }
コード例 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (client.Connected)
            {
                ChatMessage msg = new ChatMessage();
                msg.MessageType = MessageType.mtLogout;

                msg.UserInfo             = new UserInfo[1];
                msg.UserInfo[0].UserName = userInfo.UserName;
                msg.UserInfo[0].UserId   = userInfo.UserId;

                client.Write(ChatSocketService.ChatSocketService.SerializeMessage(msg));

                UpdateList("Disconnecting!");

                Thread.Sleep(1000);

                client.Disconnect();

                if (!client.Connected)
                {
                    UpdateList("Disconnected!");
                }
                else
                {
                    UpdateList("Not Disconnected! " + client.LastException != null ? client.LastException.Message : String.Empty);
                }

                this.lstUsers.Items.Clear();

                Application.DoEvents();

                read.Join();
                read = null;

                Application.DoEvents();
            }
        }
コード例 #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (client.Connected)
            {
                client.Disconnect();

                if (!client.Connected)
                {
                    UpdateList("Disconnected!");
                }
                else
                {
                    UpdateList("Not Disconnected! " + client.LastException != null ? client.LastException.Message : String.Empty);
                }

                read.Join();
                read = null;
            }
        }