private void GetThread() { Exception ex = null; while (true) { //Loop through clients try { foreach (var client in clients) { try { if (!client.client.Connected) { //Disconnected client.client.Close(); client.client.Dispose(); clients.Remove(client); } RSN_Packet packet = RSN_Packet.AwaitPacketOverStream(client.stream); //All response actions must take place here. OnGotData(client, packet); } catch (Exception innerEx) { ex = innerEx; } } } catch { //This is always an error from the foreach. Just do it again } } }
private void GetThread() { while (true) { if (!client.Connected) { //Not connected! OnError(RSN_Exception_ErrorType.ConnectionLoss, "Connection to the server was lost.", null); } try { RSN_Packet packet = RSN_Packet.AwaitPacketOverStream(networkReader); if (packet != null) { //Got packet. OnGotMessage(packet); } } catch (Exception ex) { OnError(RSN_Exception_ErrorType.Exception, "", ex); } } }