/// <summary> /// Receives the ack. /// </summary> /// <returns> /// The ack. /// </returns> private byte receiveAck() { Console.WriteLine("receiveAck()"); recvSize = link.receive(ref buffer); dataReceived = true; if (recvSize == (int)TransSize.ACKSIZE) { Console.WriteLine("Acksize correct"); dataReceived = false; if (!checksum.checkChecksum(buffer, (int)TransSize.ACKSIZE) || buffer[(int)TransCHKSUM.TYPE] != (int)TransType.ACK) { Console.WriteLine("Error in received ack"); ack_seqNo = (byte)((ack_seqNo + 1) % 2); //increment if error } else { ack_seqNo = (byte)buffer[(int)TransCHKSUM.SEQNO]; // no increment if no error } } Console.WriteLine("ack_seqNo" + ack_seqNo.ToString()); return(ack_seqNo); }
/// <summary> /// Receives the ack. /// </summary> /// <returns> /// The ack. /// </returns> private bool receiveAck() { recvSize = link.receive(ref buffer); dataReceived = true; if (recvSize == (int)TransSize.ACKSIZE) { dataReceived = false; if (!checksum.checkChecksum(buffer, (int)TransSize.ACKSIZE) || buffer[(int)TransCHKSUM.SEQNO] != seqNo || buffer[(int)TransCHKSUM.TYPE] != (int)TransType.ACK) { return(false); } seqNo = (byte)((buffer[(int)TransCHKSUM.SEQNO] + 1) % 2); } return(true); }
/// <summary> /// Receives the ack. /// </summary> /// <returns> /// The ack. /// </returns> private byte receiveAck() { byte[] buf = new byte[(int)TransSize.ACKSIZE]; int size = link.receive(ref buf); if (size != (int)TransSize.ACKSIZE) { return(DEFAULT_SEQNO); } if (!checksum.checkChecksum(buf, (int)TransSize.ACKSIZE) || buf [(int)TransCHKSUM.SEQNO] != seqNo || buf [(int)TransCHKSUM.TYPE] != (int)TransType.ACK) { return(DEFAULT_SEQNO); } return(seqNo); }
private bool receiveAck() { recvSize = link.Receive(ref buffer); dataReceived = true; //Note that receiveSize must be four - otherwise true i returned. This may be a bug. if (recvSize == (int)TransSize.ACKSIZE) { dataReceived = false; if (!checksum.checkChecksum(buffer, (int)TransSize.ACKSIZE) || buffer[(int)TransCHKSUM.SEQNO] != seqNo || buffer[(int)TransCHKSUM.TYPE] != (int)TransType.ACK) { return(false); //No valid ACK has been received } seqNo = (byte)((buffer[(int)TransCHKSUM.SEQNO] + 1) % 2); } return(true); //ACK received }
/// <summary> /// Receives the ack. /// </summary> /// <returns> /// The ack. /// </returns> private bool ReceiveAck() { _recvSize = _link.Receive(ref _buffer); _dataReceived = true; if (_recvSize == (int)TransSize.ACKSIZE) { _dataReceived = false; if (!_checksum.checkChecksum(_buffer, (int)TransSize.ACKSIZE) || _buffer [(int)TransCHKSUM.SEQNO] != _seqNo || _buffer [(int)TransCHKSUM.TYPE] != (int)TransType.ACK) { return(false); } _seqNo = (byte)((_buffer[(int)TransCHKSUM.SEQNO] + 1) % 2); } return(true); }
/// <summary> /// Receives the ack. /// </summary> /// <returns> /// The ack. /// </returns> private bool receiveAck() { byte[] buf = new byte[(int)TransSize.ACKSIZE]; int size = link.receive(ref buf); if (size != (int)TransSize.ACKSIZE) { return(false); } if (!checksum.checkChecksum(buf, (int)TransSize.ACKSIZE) || buf[(int)TransCHKSUM.SEQNO] != seqNo || buf[(int)TransCHKSUM.TYPE] != (int)TransType.ACK) { return(false); } seqNo = (byte)((buf[(int)TransCHKSUM.SEQNO] + 1) % 2); return(true); }
public int Receive(ref byte[] buff) { var readSize = 0; while (readSize == 0 && _errorCount < 5) { try { while ((readSize = _link.Receive(ref _buffer)) > 0) { if (_checksum.checkChecksum(_buffer, readSize)) { SendAck(true); if (_buffer[(int)TransCHKSUM.SEQNO] == _seqNr) { NextSeqNo(); readSize = buff.Length < readSize - (int)TransSize.ACKSIZE ? buff.Length : readSize - (int)TransSize.ACKSIZE; Array.Copy(_buffer, (int)TransSize.ACKSIZE, buff, 0, readSize); break; } continue; } SendAck(false); } } catch (TimeoutException) { readSize = 0; _errorCount++; } } _errorCount = 0; return(readSize); }