public void Close() { IsRunning = false; if (SocketFrom != null) { if (SocketFrom.Connected) { try { SocketFrom.Shutdown(SocketShutdown.Both); } catch {; } Thread.Sleep(100); try { SocketFrom.Close(); } catch {; } } SocketFrom = null; } if (SocketTo != null) { if (SocketTo.Connected) { try { SocketTo.Shutdown(SocketShutdown.Both); } catch {; } Thread.Sleep(100); try { SocketTo.Close(); } catch {; } } SocketTo = null; } }
public byte[] ReadByte() { if (SocketFrom != null) { int count = 0; try { count = SocketFrom.Receive(bufferRead); } catch { count = 0; } if (count != 0) { if (userFrom != null) { // check speed limit speedSignal += count; // reduce use of lock (Conf.Users.CheckSpeed().lock) if (speedSignal > speedCheckThreshold) { Conf.Users[userFrom].CheckSpeed(speedSignal); speedSignal = 0; } } byte[] tmpBuffer = new byte[count]; Array.Copy(bufferRead, tmpBuffer, count); if (EncryptFrom) { tmpBuffer = Decrypt(tmpBuffer); } return(tmpBuffer); } } return(null); }
public byte[] ReadByte() { byte[] result = null; if (SocketFrom != null && SocketFrom.Connected) { int count; try { count = SocketFrom.Receive(bufferRead); } catch { count = 0; } if (count > 0) { byte[] tmpBuffer = new byte[count]; Array.Copy(bufferRead, tmpBuffer, count); if (EncryptFrom) { tmpBuffer = Decrypt(tmpBuffer); } result = tmpBuffer; if (UserFrom != null) { // check speed limit speedSignal += result.Length; // reduce use of lock (Conf.Users.CheckSpeed().lock) if (speedSignal > speedCheckThreshold) { Conf.Users[UserFrom].CheckSpeed(speedSignal); speedSignal = 0; } } } } return(result); }