Пример #1
0
 public void Close()
 {
     // send endmessage to client, disconnect, abort client threat
     Send(endMessage);
     Clientsocket.Close(1);
     clientReceiveThread.Abort();
 }
Пример #2
0
 public void Disconnect()
 {
     Clientsocket.Shutdown(SocketShutdown.Both);
     Clientsocket.Close();
     //清空数据
     Clientsocket        = null;
     isReceiveProcessing = false;
     clientdataCache.Clear();
 }
Пример #3
0
        private void Receive()
        {
            string message = "";

            while (!message.Contains(endMessage))
            {
                int length = Clientsocket.Receive(buffer);
                message = Encoding.UTF8.GetString(buffer, 0, length);
                if (Name == null && message.Contains(":"))
                {
                    Name = message.Split(':')[0];
                }

                action(message, Clientsocket);
            }
            Close();
        }
Пример #4
0
        private void Receive()
        {
            string message = "";

            while (!message.Equals(endMessage))
            {
                int length = Clientsocket.Receive(buffer);
                message = Encoding.UTF8.GetString(buffer, 0, length);
                //set name prop if not already done
                if (Name == null && message.Contains(":"))
                {
                    Name = message.Split(':')[0];
                }
                //inform GUI via delegate
                action(message, Clientsocket);
            }
            Close();
        }
Пример #5
0
        /// <summary>
        /// 发送数据包
        /// </summary>
        private void sendPacket()
        {
            isSendProcess = true;

            if (sendQueue.Count == 0)//递归结束条件
            {
                isSendProcess = false;
                return;
            }

            byte[] packet = sendQueue.Dequeue();
            SendArgs.SetBuffer(packet, 0, packet.Length);
            bool result = Clientsocket.SendAsync(SendArgs);//异步发送消息

            if (!result)
            {
                processSend();
            }
        }
Пример #6
0
 public void Send(string message)
 {
     Clientsocket.Send(Encoding.UTF8.GetBytes(message));
 }