otsdaq  3.09.00
ots::TransceiverSocket Class Reference
+ Inheritance diagram for ots::TransceiverSocket:
+ Collaboration diagram for ots::TransceiverSocket:

Public Member Functions

 TransceiverSocket (std::string IPAddress, unsigned int port=0)
 
int acknowledge (const std::string &buffer, bool verbose=false, size_t maxChunkSize=1500, unsigned int interPacketGapUSeconds=0, bool enableRetransmission=false)
 
int sendAll (const std::string &buffer, bool verbose=false, size_t maxChunkSize=65500, unsigned int interPacketGapUSeconds=0)
 
int receiveAll (std::string &buffer, unsigned int timeoutSeconds=5, unsigned int retransmitMaxRetries=10, bool verbose=false)
 
std::string sendAndReceive (Socket &toSocket, const std::string &sendBuffer, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=false, unsigned int interPacketTimeoutUSeconds=10000)
 
std::string sendAndReceiveAll (Socket &toSocket, const std::string &sendBuffer, unsigned int timeoutSeconds=5, unsigned int retransmitMaxRetries=10, bool verbose=false)
 
- Public Member Functions inherited from ots::TransmitterSocket
 TransmitterSocket (const std::string &IPAddress, unsigned int port=0)
 
int send (Socket &toSocket, const std::string &buffer, bool verbose=false)
 
int send (Socket &toSocket, const std::vector< uint32_t > &buffer, bool verbose=false)
 
int send (Socket &toSocket, const std::vector< uint16_t > &buffer, bool verbose=false)
 
- Public Member Functions inherited from ots::Socket
 Socket (const std::string &IPAddress, unsigned int port=0)
 
virtual void initialize (unsigned int socketReceiveBufferSize=defaultSocketReceiveSize_)
 
const struct sockaddr_in & getSocketAddress (void)
 
const std::string & getIPAddress ()
 
uint16_t getPort ()
 
bool isInitialized ()
 
- Public Member Functions inherited from ots::ReceiverSocket
 ReceiverSocket (std::string IPAddress, unsigned int port=0)
 
int flush ()
 
int receive (std::string &buffer, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=false)
 returns count of dropped packets
 
int receive (std::vector< uint32_t > &buffer, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=false)
 
int receive (std::string &buffer, unsigned long &fromIPAddress, unsigned short &fromPort, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=false)
 
int receive (std::vector< uint32_t > &buffer, unsigned long &fromIPAddress, unsigned short &fromPort, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=false)
 
std::string getLastIncomingIPAddress (void)
 
unsigned short getLastIncomingPort (void)
 

Static Public Attributes

static constexpr uint16_t RETRANSMIT_MAGIC = 0xD2C4
 Retransmission protocol constants.
 
static constexpr size_t RETRANSMIT_HEADER_SIZE = 8
 

Additional Inherited Members

- Protected Types inherited from ots::Socket
enum  { maxSocketSize_ = 65536 , defaultSocketReceiveSize_ = 0x10000 }
 
enum  { FirstSocketPort = 10000 , LastSocketPort = 15000 }
 
- Protected Member Functions inherited from ots::Socket
 Socket (void)
 protected constructor
 
- Protected Member Functions inherited from ots::ReceiverSocket
 ReceiverSocket (void)
 protected constructor
 
- Protected Attributes inherited from ots::Socket
struct sockaddr_in socketAddress_
 
int socketNumber_
 
std::string IPAddress_
 
unsigned int requestedPort_
 
bool isInitialized_ = false
 

Detailed Description

Definition at line 12 of file TransceiverSocket.h.

Member Function Documentation

◆ acknowledge()

int TransceiverSocket::acknowledge ( const std::string &  buffer,
bool  verbose = false,
size_t  maxChunkSize = 1500,
unsigned int  interPacketGapUSeconds = 0,
bool  enableRetransmission = false 
)

acknowledge() responds to last receive location. When enableRetransmission is true, delegates to sendAll() for reliable multi-packet transfer with retransmit handling.

returns 0 on success When enableRetransmission is true, uses sendAll() to send the buffer with retransmission headers, then waits for retransmit requests from the receiver.

Definition at line 39 of file TransceiverSocket.cc.

◆ receiveAll()

int TransceiverSocket::receiveAll ( std::string &  buffer,
unsigned int  timeoutSeconds = 5,
unsigned int  retransmitMaxRetries = 10,
bool  verbose = false 
)

receiveAll() receives a multi-packet retransmission-mode response. It assembles the full message from individually-headered packets, detects missing packets by index, and requests retransmission from the sender for any dropped packets. Returns 0 on success (assembled buffer placed in 'buffer'), -1 on failure.

receiveAll() receives a multi-packet retransmission-mode response. Packets are expected to have an 8-byte retransmission header: [0-1] magic 0xD2C4 (network byte order) [2-3] packet index (network byte order uint16) [4-5] total packets (network byte order uint16) [6-7] payload size (network byte order uint16)

After all initial packets are received (or timeout), missing packets are identified and a retransmit request is sent back to the sender containing the magic marker followed by the list of missing packet indices. This repeats up to retransmitMaxRetries times. When all packets are received, a "done" signal (magic + 0xFFFF) is sent to the sender.

Returns 0 on success (assembled buffer placed in 'buffer'), -1 on failure.

Definition at line 384 of file TransceiverSocket.cc.

◆ sendAll()

int TransceiverSocket::sendAll ( const std::string &  buffer,
bool  verbose = false,
size_t  maxChunkSize = 65500,
unsigned int  interPacketGapUSeconds = 0 
)

sendAll() sends a buffer to the last receive address using the retransmission protocol. This is fully self-contained: it builds headered packets, sends them all, then waits for retransmit requests from the receiver and resends any missing packets. Only returns when the transfer is complete (receiver sends "done") or timeout expires.

Each packet is prepended with an 8-byte retransmission header: [0-1] magic marker 0xD2C4 (network byte order) [2-3] packet index (0-based, network byte order uint16) [4-5] total packet count (network byte order uint16) [6-7] payload size in this packet (network byte order uint16)

Returns 0 on success.

sendAll() sends a buffer to the last receive address (fromAddress_) using the retransmission protocol. Fully self-contained:

  1. Builds all packets with 8-byte retransmission headers
  2. Sends all packets
  3. Waits for retransmit requests from the receiver
  4. Resends requested packets
  5. Returns when receiver sends "done" or timeout expires

Returns 0 on success.

Definition at line 111 of file TransceiverSocket.cc.

◆ sendAndReceive()

std::string TransceiverSocket::sendAndReceive ( Socket toSocket,
const std::string &  sendBuffer,
unsigned int  timeoutSeconds = 1,
unsigned int  timeoutUSeconds = 0,
bool  verbose = false,
unsigned int  interPacketTimeoutUSeconds = 10000 
)

Receives one packet with the specified timeout, then attempts to receive additional packets with interPacketTimeoutUSeconds timeout to handle multi-packet responses. Returns the combined received buffer or throws on error/timeout.

Definition at line 295 of file TransceiverSocket.cc.

◆ sendAndReceiveAll()

std::string TransceiverSocket::sendAndReceiveAll ( Socket toSocket,
const std::string &  sendBuffer,
unsigned int  timeoutSeconds = 5,
unsigned int  retransmitMaxRetries = 10,
bool  verbose = false 
)

sendAndReceiveAll() sends a command then uses the retransmission protocol to reliably receive the full multi-packet response. The sender must use acknowledge() with enableRetransmission=true (or sendAll()). This method:

  1. Flushes and sends the request
  2. Receives all retransmission-headered packets
  3. Detects missing packets and sends retransmit requests
  4. Assembles and returns the complete response Throws on timeout or error.

sendAndReceiveAll() sends a command then reliably receives the full multi-packet response using the retransmission protocol. The remote sender must use acknowledge() with enableRetransmission=true.

This mirrors sendAndReceive() but uses receiveAll() instead of the simple multi-packet loop, providing:

  • Packet ordering via indexed headers
  • Dropped packet detection via known total count
  • Automatic retransmit requests for missing packets
  • Fully assembled, ordered response buffer

Throws on timeout or error.

Definition at line 674 of file TransceiverSocket.cc.


The documentation for this class was generated from the following files: