#include <rtthread.h>
#include <sys/socket.h>
#include <netdb.h>
#include <string.h>
#include <finsh.h>
const char send_data[] = "This is UDP Client from RT-Thread.\n";
void udpclient(int argc, char **argv)
{
int sock, port, count;
const char *url;
if (argc < 3)
{
rt_kprintf(
"Usage: udpclient URL PORT [COUNT = 10]\n");
rt_kprintf(
"Like: tcpclient 192.168.12.44 5000\n");
return ;
}
url = argv[1];
port = strtoul(argv[2], 0, 10);
if (argc > 3)
count = strtoul(argv[3], 0, 10);
else
count = 10;
if ((sock =
socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{
return;
}
while (count)
{
sendto(sock, send_data, strlen(send_data), 0,
count --;
}
}