|
static ipa_t | ipAddress (const char *) |
| Return the IP address for the string pointed to by ips. More...
|
|
static string | ip2string (ipa_t) |
| Create a string representation of an IP address. More...
|
|
static bool | readIpAdr (istream &, ipa_t &) |
| If next thing on the current line is an ip address, return it in ipa and return true. More...
|
|
static ipa_t | getIpAdr (const char *) |
| Get the default IP address of a specified host. More...
|
|
static ipa_t | myIpAddress () |
| Get the default IP address of this host. More...
|
|
static void | initSockAdr (ipa_t, ipp_t, sockaddr_in *) |
| Initialize a socket address structure with a specified IP address and port number. More...
|
|
static void | extractSockAdr (sockaddr_in *, ipa_t &, ipp_t &) |
| Extract an IP address and port number from a socket address structure. More...
|
|
static ipp_t | getSockPort (int) |
| Get the local port number associated with a given socket. More...
|
|
static ipa_t | getSockIp (int) |
| Get the local IP address associated with a given socket. More...
|
|
static ipa_t | getPeerIp (int) |
| Get the IP address of the peer for a given socket. More...
|
|
static int | datagramSocket () |
| Open a datagram socket. More...
|
|
static int | streamSocket () |
| Open a stream socket. More...
|
|
static bool | bind4d (int, ipa_t, ipp_t) |
| Bind a socket to a specified address and port. More...
|
|
static bool | listen4d (int) |
| Listen for a stream connection. More...
|
|
static int | accept4d (int) |
| Accept the next waiting connection request. More...
|
|
static int | accept4d (int, ipa_t &, ipp_t &) |
| Accept the next waiting connection request. More...
|
|
static bool | connect4d (int, ipa_t, ipp_t) |
| Connect to a remote host. More...
|
|
static bool | nonblock (int) |
| Configure a socket to be nonblocking. More...
|
|
static int | sendto4d (int, void *, int, ipa_t, ipp_t) |
| Send a datagram to a remote host. More...
|
|
static int | recv4d (int, void *, int) |
| Receive a datagram from a remote host. More...
|
|
static int | recvfrom4d (int, void *, int, ipa_t &, ipp_t &) |
| Receive a datagram from a remote host. More...
|
|
static bool | hasData (int) |
| Test a socket to see if it has data to be read. More...
|
|
static int | dataAvail (int) |
| Determine the amount of data available for reading from socket. More...
|
|
static int | spaceAvail (int) |
| Determine the space available for writing on a socket. More...
|
|
static bool | recvInt (int, uint32_t &) |
| Read a 32 bit integer from a stream socket. More...
|
|
static bool | sendInt (int, uint32_t) |
| Send a 32 bit integer on a stream socket. More...
|
|
static bool | recvIntBlock (int, uint32_t &) |
|
static bool | sendIntBlock (int, uint32_t) |
|
static bool | recvIntVec (int, uint32_t *, int) |
| Receive a vector of 32 bit integers on a stream socket. More...
|
|
static bool | sendIntVec (int, uint32_t *, int) |
| Send a vector of 32 bit integers on a stream socket. More...
|
|
static int | recvBuf (int, char *, int) |
| Receive a "chunk" of data on a stream socket. More...
|
|
static int | sendBuf (int, char *, int) |
|
static int | recvBufBlock (int, char *, int) |
|
static int | sendBufBlock (int, char *, int) |
|
static int | sendString (int, const string &) |
| Send a string over a blocking stream socket. More...
|
|
Network programming for dummies.
This class defines a library of routines for IPv4 network programming, that hides much of the ugliness of the standard system calls. The big advantage is that you can avoid socket address structures completely.
Many of the routines are just wrappers on the standard system calls with more intuitive interfaces.
Definition at line 34 of file Np4d.h.
int forest::Np4d::recvBuf |
( |
int |
sock, |
|
|
char * |
buf, |
|
|
int |
buflen |
|
) |
| |
|
static |
Receive a "chunk" of data on a stream socket.
This method is intended for use on nonblocking sockets. It expects the host on the other end of the socket to send a 32 bit integer, which represents the size of the next chunk of data to expect, followed by the chunk of data. The method reads the size information, then reads the specified amount of data into the provided buffer. For example, to send 20 bytes of data, the remote host sends the 32 bit integer 20, followed by the 20 bytes of data, for a total of 24 bytes.
- Parameters
-
sock | is the number of the socket |
is | a pointer to a buffer |
buflen | specifies the size of the buffer |
- Returns
- the number of bytes actually read on success; 0 if the underlying recv call returned 0, or -1 on an error or if the next complete chunk is not available
If the chunk size specified in the input stream exceeds buflen, the method will only read and return buflen bytes.
Definition at line 416 of file Np4d.cpp.