| Summary |
#include <rtl.h>
BOOL udp_send (
U8 socket, /* UDP socket to send the data packet from. */
U8* remip, /* Pointer to the IP address of the remote machine. */
U16 remport, /* Port number of remote machine to send the data to. */
U8* buf, /* Pointer to buffer containing the data to send. */
U16 dlen ); /* Number of bytes of data to send. */
|
| Description | The udp_send function sends the data packet to a remote machine. The argument socket specifies the socket handle to use for communication on the local machine. The argument remip points to a buffer containing the four octets that make up the ip address of the remote machine. The argument remport specifies the port on the remote machine to send the data packet to. The argument buf points to the constructed UDP data packet. The argument dlen specifies the number of bytes in the data packet to send. The udp_send function is in the RL-TCPnet library. The prototype is defined in rtl.h. note - You must allocate the memory using udp_get_buf before calling udp_send.
- The socket must already be open for communication before you can send data.
- The same UDP socket, using the same local port, can communicate with several remote machines using UDP ports. The user application must handle proper multiplexing of outgoing packets and demultiplexing of received packets.
|
| Example |
#include <rtl.h>
#include <string.h>
void send_data () {
char udp_msg[] = {"Hello World!"};
U8 remip[4] = {192,168,1,100};
U8 *sendbuf;
U16 len;
len = strlen (udp_msg);
sendbuf = udp_get_buf (len);
str_copy (sendbuf, udp_msg);
/* Send 'Hello World!' to remote peer */
udp_send (udp_soc, remip, 1000, sendbuf, len);
}
|