Sleipnir
|
Utilities for sending and receiving data over the network. More...
#include <seeknetwork.h>
Static Public Member Functions | |
static int | Send (int, const string &) |
Send a string. | |
static int | Send (int, const vector< float > &) |
Send a float array. | |
static int | Send (int, char *, int) |
Low-level send function. | |
static void | Clear (char *, int) |
Clear a char array. | |
static int | Copy (char *, char *, int, int) |
Copy a char array. | |
static int | Receive (int, string &) |
Receive a string. | |
static int | Receive (int, vector< float > &) |
Receive a float array. |
Utilities for sending and receiving data over the network.
This class provides static utility functions to facilitate the exchange of messages between the Seek client and the Seek server. In order to allow this exchange to occur, all messages must conform to a uniform standard.
On the sending end, all outgoing messages must first begin with a message header that specifies the length and the type of the message. Then the body of the message follows.
The supported outgoing messages are: an array of chars
(such as a string
), an array of floats
. The outgoing message is structured as follows:
unsigned
integer
that specifies the size of one element (S). (1 for a char
, 4 for a float
) unsigned
integer
that specifies the total number of elements to be sent (N). (1 for a single-value, otherwise the size of the array) IMPORTANT: Outgoing messages are always encoded using bytes in the Little Endian order.
On the receiving end, CSeekNetwork also supports the receiving of a char
array (or a string
) or a float
array.
In order to be properly recognized, the incoming message should be structured as follows:
For a char
array:
signed
integer
that specifies the length of the char
array to receive (NC) char
array.For a float
array:
signed
integer
that specifies the length of the float
array to receive (NF) float
array.IMPORTANT: For an incoming message to be properly recognized, the incoming message should also be encoded with bytes in the Little Endian order.
Definition at line 59 of file seeknetwork.h.
void Sleipnir::CSeekNetwork::Clear | ( | char * | b, |
int | size | ||
) | [static] |
Clear a char array.
Clears a char array by zeroing all bytes
b | The char array |
size | The size of the char array |
Definition at line 90 of file seeknetwork.cpp.
int Sleipnir::CSeekNetwork::Copy | ( | char * | d, |
char * | s, | ||
int | beg, | ||
int | num | ||
) | [static] |
Copy a char array.
Copies the entire source array (0...N) to the destination array beginning at the index beg
d | The destination |
s | The source |
beg | The position on the destination array where the pasting starts |
num | The size of the source array |
beg
+ num
Definition at line 97 of file seeknetwork.cpp.
Referenced by Send().
int Sleipnir::CSeekNetwork::Receive | ( | int | new_fd, |
string & | s | ||
) | [static] |
Receive a string.
Receive a string from the client
new_fd | The client socket |
s | The string where the message will be received to |
Definition at line 161 of file seeknetwork.cpp.
int Sleipnir::CSeekNetwork::Receive | ( | int | new_fd, |
vector< float > & | f | ||
) | [static] |
Receive a float array.
Receive a float array from the client
new_fd | The client socket |
f | The float array where the message will be received to |
Definition at line 105 of file seeknetwork.cpp.
int Sleipnir::CSeekNetwork::Send | ( | int | new_fd, |
const string & | str | ||
) | [static] |
Send a string.
Encodes an outgoing message and sends it to the client
new_fd | The client socket |
str | The string to be sent to the client |
Definition at line 15 of file seeknetwork.cpp.
Referenced by Sleipnir::CSeekTools::ReadDatabaselets(), and Send().
int Sleipnir::CSeekNetwork::Send | ( | int | new_fd, |
const vector< float > & | f | ||
) | [static] |
Send a float array.
Encodes an outgoing message and sends it to the client
new_fd | The client socket |
str | The array of floats to be sent to the client |
Definition at line 38 of file seeknetwork.cpp.
References Send().
int Sleipnir::CSeekNetwork::Send | ( | int | new_fd, |
char * | c, | ||
int | size | ||
) | [static] |
Low-level send function.
new_fd | The client socket |
c | The message |
size | The message length |
size
if the sending is successfulDefinition at line 66 of file seeknetwork.cpp.
References Copy().