internal void ReceiveCallback(IAsyncResult ar) { bool continueReceive = true; int count = 0; try { count = Socket.EndReceive(ar); } catch (SocketException) { OnConnectLost(); return; } catch (Exception ex) { try { OnErrorOccurred(ex); } catch { return; } } try { if (count == 0) { return; } switch (ReceiveBuf[0]) { case Consts.StringHeader: continueReceive = OnCommandReceived(ReceiveBuf.ToFtString()); break; default: throw new FormatException("Bad Header!"); } } catch (Exception ex) { OnErrorOccurred(ex); } if (continueReceive) { BeginReceive(); } }
internal string ReceiveString() { int count; try { count = Socket.EndReceive(BeginReceive()); } catch (Exception) { OnConnectLost(); throw; } if (count == 0) { return(null); } return(ReceiveBuf.ToFtString()); }