public void Close() { // send endmessage to client, disconnect, abort client threat Send(endMessage); Clientsocket.Close(1); clientReceiveThread.Abort(); }
public void Disconnect() { Clientsocket.Shutdown(SocketShutdown.Both); Clientsocket.Close(); //清空数据 Clientsocket = null; isReceiveProcessing = false; clientdataCache.Clear(); }
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(); }
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(); }
/// <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(); } }
public void Send(string message) { Clientsocket.Send(Encoding.UTF8.GetBytes(message)); }