# H3DNetworkingUtils::Packet Class Reference

The payload data holds the field value. More...

`#include <H3DNetworkingUtils/Packet.h>`

List of all members.

## Public Member Functions
| Packet (int sz=128)
| Constructor.
| Packet (Packet const &other)
| Copy Constructor.
Packet & | operator= (Packet const &other)
| Copy operator.
void | write (void *data, int num)
| Write data into packet.
bool | send (TCPSock *sockP)
| Sends packet to a remote host via TCP Returns true on success.
bool | send (UDPSock *sockP, InetAddr *remote_end)
| Sends packet to a remote host via UDP Returns true on success.
void | clear ()
| Call this after finishing with data inside - (send already does this).
bool | receive (TCPSock *sockP)
| Receive data from socket into packet Returns false on failure, true on success.
int | receive (UDPSock *sockP, InetAddr *remote_end)
| Reads packet from any remote host via UDP Fills 'remote_end' Returns -1 on failure, 0 on timeout, num received on success.
void | read (void *dest, int num_bytes)
| Read data from packet.
int | readInt16 () const
| get a 16 bit integer from the packet buffer.
void | writeInt16 (int const &val)
| Put a 16 bit integer into the packet buffer.
bool | isHeartBeat () const
| Returns true if this packet is just a 'heart beat' packet, letting server know client is still alive.
void | setHeartBeat ()
| Sets this packet to be a 'heart beat' packet, letting server know client is still alive.
int | getId () const
| returns the Id but doesn't change the read position for the next read.
short | getSeqNum () const
| returns the sequence number but doesn't change the read position for the next read.
void | setId (int id)
| sets the packet's Id.
void | setSeqNum (short seq)
| sets the packet's sequence number.
void | stretchBuffer (u_int extra_size)
| Increase the buffer by the extra size (plus a bit!).

## Detailed Description

The payload data holds the field value.

The Packet class contains a packet for sending or receiving across a network.

It is filled with the write functions and read with the read functions. Each time you call a write function, a marker is progressed, marking the current end of the buffer. Each time you call a read function a different marker is progressed in the buffer. A packet can be set to be a heartBeat packet, which has a special id which is sent periodically in the casew of UDP sockets to tell the other end that it is still alive.

with TCP or UDP.
"Read" implies getting data out of the packet.
"Write" implies putting data into the packet.
"receive" implies getting data from the socket into the packet.
"send" implies putting data from the packet to the socket.
A packet consists of a header and payload.
The header holds:
size (only used on TCP sockets) internal code sets this
sequence number (only used on UDP sockets) use setSeqNum() getSeqNum()
packet id use setId() getId()

## Member Function Documentation

bool Packet::send | ( | TCPSock * | sockP | ) |

Sends packet to a remote host via TCP
Returns true on success.

References clear().

Referenced by H3DNetworkingUtils::RemoteUDPServer::receiveLoop(), H3DNetworkingUtils::RemoteUDPServer::sendLoop(), H3DNetworkingUtils::RemoteUDPClient::sendLoop(), H3DNetworkingUtils::RemoteUDPServer::sendThisPacket(), and H3DNetworkingUtils::RemoteUDPClient::sendThisPacket().

bool Packet::send | ( | UDPSock * | sockP,
|  | InetAddr * | remote_end |
| ) |  |  |

Sends packet to a remote host via UDP
Returns true on success.

References clear().

bool Packet::receive | ( | TCPSock * | sockP | ) |

Receive data from socket into packet
Returns false on failure, true on success.

References stretchBuffer().

Referenced by H3DNetworkingUtils::RemoteUDPServer::receiveLoop(), H3DNetworkingUtils::RemoteUDPClient::receiveLoop(), and H3DNetworkingUtils::RemoteUDPClient::sendLoop().

int Packet::receive | ( | UDPSock * | sockP,
|  | InetAddr * | remote_end |
| ) |  |  |

Reads packet from any remote host via UDP
Fills 'remote_end'
Returns -1 on failure, 0 on timeout, num received on success.

bool H3DNetworkingUtils::Packet::isHeartBeat | ( |  | ) | const`[inline]`

Returns true if this packet is just a 'heart beat' packet, letting server know client is still alive.

Referenced by H3DNetworkingUtils::RemoteUDPServer::receiveLoop(), and H3DNetworkingUtils::RemoteUDPClient::receiveLoop().

void Packet::setHeartBeat | ( |  | ) |

Sets this packet to be a 'heart beat' packet, letting server know client is still alive.

References setId().

Referenced by H3DNetworkingUtils::RemoteUDPClient::RemoteUDPClient(), and H3DNetworkingUtils::RemoteUDPServer::RemoteUDPServer().

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

- Packet.h
- Packet.cpp