コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!client.Connected)
            {
                client.RemoteEndPoint = new IPEndPoint(IPAddress.Parse(txtHost.Text), 8090);

                client.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive;
                client.Delimiter     = new byte[] { 0xAA, 0xFF, 0xAA };

                client.EncryptType     = EncryptType.etRijndael;
                client.CompressionType = CompressionType.ctNone;

                client.SocketBufferSize  = 1024;
                client.MessageBufferSize = 512;

                client.Connect();

                if (client.Connected)
                {
                    this.lstUsers.Items.Clear();
                    this.lstStatus.Items.Clear();

                    read = new Thread(new ParameterizedThreadStart(ThreadExecute));
                    read.Start(client);

                    ChatMessage msg = new ChatMessage();
                    msg.MessageType = MessageType.mtLogin;

                    msg.UserInfo             = new UserInfo[1];
                    msg.UserInfo[0].UserName = txtNickName.Text;

                    client.Write(ChatSocketService.ChatSocketService.SerializeMessage(msg));
                }
                else
                {
                    UpdateList("Not Connected! " + client.LastException != null ? client.LastException.Message : String.Empty);
                }
            }
        }
コード例 #2
0
        private void button3_Click_1(object sender, EventArgs e)
        {
            if (client.Connected)
            {
                client.Write(txtMessage.Text);

                if (client.LastException != null)
                {
                    UpdateList("Write Error! " + client.LastException.Message);
                }
                else
                {
                    UpdateList("Write -> " + txtMessage.Text);
                }
            }
        }