private CommunicationResult TryRead(string ipPort, int count, bool doEncryption) { ReadResult result = server.ReadWithTimeout(maxPingMs, ipPort, count); TTInstruction ins = TTInstruction.Empty; byte[] buffer = null; if (result.Status != ReadResultStatus.Success) { throw new FailedReceivingException($"Did not receive response ({result.Status})."); } if (doEncryption && clientEncryptor != null) { buffer = clientEncryptor.AESDecryptBytes(result.Data); } else { buffer = result.Data; } byte[] dat = null; if (!TTNet.UnpackTCPBuffer(buffer, ref ins, ref dat)) { throw new FailedReceivingException($"Received invalid response."); } return(new CommunicationResult(ins, dat)); }
private CommunicationResult TryRead(int count, int?overrideTimeoutMs = null) { int timeout = overrideTimeoutMs ?? maxPingMs; ReadResult result = client.ReadWithTimeout(timeout, count); if (result.Status != ReadResultStatus.Success) { throw new FailedReceivingException($"Did not receive response ({result.Status})."); } TTInstruction ins = TTInstruction.Empty; byte[] dat = null; if (!TTNet.UnpackTCPBuffer(result.Data, ref ins, ref dat)) { throw new FailedReceivingException($"Received invalid response."); } return(new CommunicationResult(ins, dat)); }