void ReceiveThread() { string receiveString; int count; try { while (true) { count = stream.Read(buffer, 0, buffer.Length); // Block -------------------------------- if (count <= 0) { Log("Disconnected from client."); _Server.CloseConnection(this); return; } receiveString = Encoding.UTF8.GetString(buffer, 0, count); Log($"Receive{client.Client.LocalEndPoint}:{receiveString}"); bufferString += receiveString; Match match = PacketCutter.Match(bufferString); while (match.Success) { CallProcess(match.Groups[1].Value, this); bufferString = match.Groups[2].Value; match = PacketCutter.Match(bufferString); } } } catch (ThreadAbortException) { Log("Receive Thread Aborted."); } catch (SocketException ex) { Server.Log(ex); _Server.CloseConnection(this); } catch (Exception ex) { Server.Log(ex); _Server.CloseConnection(this); } }
void ReceiveThread() { string receiveString; int count; count = stream.Read(buffer, 0, buffer.Length); // Block -------------------------------- if (count <= 0) { Log("Disconnected from server!"); stream?.Close(); client?.Close(); client = null; return; } receiveString = Encoding.UTF8.GetString(buffer, 0, count); NetId = receiveString.Substring(0, receiveString.Length - 1); CallConnection(); try { while (true) { count = stream.Read(buffer, 0, buffer.Length); // Block -------------------------------- if (count <= 0) { Log("Disconnected from server!"); stream?.Close(); client?.Close(); client = null; CallDisconnection(); return; } receiveString = Encoding.UTF8.GetString(buffer, 0, count); Log($"Receive{client.Client.LocalEndPoint}:{receiveString}"); bufferString += receiveString; Match match = PacketCutter.Match(bufferString); while (match.Success) { CallReceive(match.Groups[1].Value); bufferString = match.Groups[2].Value; match = PacketCutter.Match(bufferString); } } } catch (ThreadAbortException) { Log("Receive Thread Aborted."); } catch (Exception ex) { Log(ex); stream?.Close(); client?.Close(); client = null; CallDisconnection(); return; } }