add more Chinese comments.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@536 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2010-03-24 15:26:48 +00:00
parent 7606f6d952
commit cd039a8b49
6 changed files with 300 additions and 245 deletions

View File

@ -1,30 +1,24 @@
/* /*
* File : readwrite.c *
* This file is part of RT-TestCase in RT-Thread RTOS
* COPYRIGHT (C) 2010, RT-Thread Development Team
* *
* The license and distribution terms for this file may be *
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2010-02-10 Bernard first version
*/ */
#include <rtthread.h> #include <rtthread.h>
#include <dfs_posix.h> #include <dfs_posix.h> /* 当需要使用文件操作时,需要包含这个头文件 */
#define TEST_FN "/test.dat" #define TEST_FN "/test.dat"
/* 测试用的数据和缓冲 */
static char test_data[120], buffer[120]; static char test_data[120], buffer[120];
/* 文件读写测试 */ /* 文件读写测试 */
void readwrite(const char* filename) void readwrite(const char* filename)
{ {
int fd; int fd;
int index, length; int index, length;
/* 只写 & 创建 打开 */ /* 只写 & 创建 打开 */
fd = open(TEST_FN, O_WRONLY | O_CREAT | O_TRUNC, 0); fd = open(TEST_FN, O_WRONLY | O_CREAT | O_TRUNC, 0);
if (fd < 0) if (fd < 0)
{ {
@ -32,13 +26,13 @@ void readwrite(const char* filename)
return; return;
} }
/* 准备写入数据 */ /* 准备写入数据 */
for (index = 0; index < sizeof(test_data); index ++) for (index = 0; index < sizeof(test_data); index ++)
{ {
test_data[index] = index + 27; test_data[index] = index + 27;
} }
/* 写入数据 */ /* 写入数据 */
length = write(fd, test_data, sizeof(test_data)); length = write(fd, test_data, sizeof(test_data));
if (length != sizeof(test_data)) if (length != sizeof(test_data))
{ {
@ -47,10 +41,10 @@ void readwrite(const char* filename)
return; return;
} }
/* 关闭文件 */ /* 关闭文件 */
close(fd); close(fd);
/* 只写并在末尾添加打开 */ /* 只写并在末尾添加打开 */
fd = open(TEST_FN, O_WRONLY | O_CREAT | O_APPEND, 0); fd = open(TEST_FN, O_WRONLY | O_CREAT | O_APPEND, 0);
if (fd < 0) if (fd < 0)
{ {
@ -65,10 +59,10 @@ void readwrite(const char* filename)
close(fd); close(fd);
return; return;
} }
/* 关闭文件 */ /* 关闭文件 */
close(fd); close(fd);
/* 只读打开进行数据校验 */ /* 只读打开进行数据校验 */
fd = open(TEST_FN, O_RDONLY, 0); fd = open(TEST_FN, O_RDONLY, 0);
if (fd < 0) if (fd < 0)
{ {
@ -76,6 +70,7 @@ void readwrite(const char* filename)
return; return;
} }
/* 读取数据(应该为第一次写入的数据) */
length = read(fd, buffer, sizeof(buffer)); length = read(fd, buffer, sizeof(buffer));
if (length != sizeof(buffer)) if (length != sizeof(buffer))
{ {
@ -83,6 +78,8 @@ void readwrite(const char* filename)
close(fd); close(fd);
return; return;
} }
/* 检查数据是否正确 */
for (index = 0; index < sizeof(test_data); index ++) for (index = 0; index < sizeof(test_data); index ++)
{ {
if (test_data[index] != buffer[index]) if (test_data[index] != buffer[index])
@ -93,6 +90,7 @@ void readwrite(const char* filename)
} }
} }
/* 读取数据(应该为第二次写入的数据) */
length = read(fd, buffer, sizeof(buffer)); length = read(fd, buffer, sizeof(buffer));
if (length != sizeof(buffer)) if (length != sizeof(buffer))
{ {
@ -100,6 +98,8 @@ void readwrite(const char* filename)
close(fd); close(fd);
return; return;
} }
/* 检查数据是否正确 */
for (index = 0; index < sizeof(test_data); index ++) for (index = 0; index < sizeof(test_data); index ++)
{ {
if (test_data[index] != buffer[index]) if (test_data[index] != buffer[index])
@ -109,13 +109,15 @@ void readwrite(const char* filename)
return; return;
} }
} }
/* 检查数据完毕,关闭文件 */
/* 检查数据完毕,关闭文件 */
close(fd); close(fd);
/* 打印结果 */ /* 打印结果 */
rt_kprintf("read/write done.\n"); rt_kprintf("read/write done.\n");
} }
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
#include <finsh.h> #include <finsh.h>
/* 输出函数到finsh shell命令行中 */
FINSH_FUNCTION_EXPORT(readwrite, perform file read and write test); FINSH_FUNCTION_EXPORT(readwrite, perform file read and write test);
#endif #endif

View File

@ -14,9 +14,11 @@ static rt_thread_t tid1 = RT_NULL;
static rt_thread_t tid2 = RT_NULL; static rt_thread_t tid2 = RT_NULL;
static rt_thread_t tid3 = RT_NULL; static rt_thread_t tid3 = RT_NULL;
struct rt_event event; /* 事件控制块 */
static struct rt_event event;
void thread1_entry(void *param) /* 线程1入口函数 */
static void thread1_entry(void *param)
{ {
rt_uint32_t e; rt_uint32_t e;
@ -31,7 +33,7 @@ void thread1_entry(void *param)
} }
rt_kprintf("thread1: delay 1s to prepare second event\n"); rt_kprintf("thread1: delay 1s to prepare second event\n");
rt_thread_delay(100); rt_thread_delay(10);
/* receive second event */ /* receive second event */
if (rt_event_recv(&event, ((1 << 3) | (1 << 5)), if (rt_event_recv(&event, ((1 << 3) | (1 << 5)),
@ -41,34 +43,37 @@ void thread1_entry(void *param)
rt_kprintf("thread1: OR recv event 0x%x\n", e); rt_kprintf("thread1: OR recv event 0x%x\n", e);
} }
rt_thread_delay(50); rt_thread_delay(5);
} }
} }
void thread2_entry(void *param) /* 线程2入口函数 */
static void thread2_entry(void *param)
{ {
while (1) while (1)
{ {
rt_kprintf("thread2: send event1\n"); rt_kprintf("thread2: send event1\n");
rt_event_send(&event, (1 << 3)); rt_event_send(&event, (1 << 3));
rt_thread_delay(100); rt_thread_delay(10);
} }
} }
void thread3_entry(void *param) /* 线程3入口函数 */
static void thread3_entry(void *param)
{ {
while (1) while (1)
{ {
rt_kprintf("thread3: send event2\n"); rt_kprintf("thread3: send event2\n");
rt_event_send(&event, (1 << 5)); rt_event_send(&event, (1 << 5));
rt_thread_delay(200); rt_thread_delay(20);
} }
} }
int event_simple_init() int event_simple_init()
{ {
/* 初始化事件对象 */
rt_event_init(&event, "event", RT_IPC_FLAG_FIFO); rt_event_init(&event, "event", RT_IPC_FLAG_FIFO);
/* 创建线程1 */ /* 创建线程1 */
@ -115,6 +120,9 @@ static void _tc_cleanup()
if (tid3 != RT_NULL && tid3->stat != RT_THREAD_CLOSE) if (tid3 != RT_NULL && tid3->stat != RT_THREAD_CLOSE)
rt_thread_delete(tid3); rt_thread_delete(tid3);
/* 执行事件对象脱离 */
rt_event_detach(&event);
/* 调度器解锁 */ /* 调度器解锁 */
rt_exit_critical(); rt_exit_critical();

View File

@ -1,81 +1,95 @@
#include <rtthread.h> #include <rtthread.h>
#include <lwip/netdb.h> #include <lwip/netdb.h> /* 为了解析主机名需要包含netdb.h头文件 */
#include <lwip/sockets.h> #include <lwip/sockets.h> /* 使用BSD socket需要包含sockets.h头文件 */
static const char send_data[] = "This is TCP Client from RT-Thread."; static const char send_data[] = "This is TCP Client from RT-Thread."; /* 发送用到的数据 */
void tcpclient(const char* url, int port) void tcpclient(const char* url, int port)
{ {
char *recv_data; char *recv_data;
struct hostent *host; struct hostent *host;
int sock, bytes_received; int sock, bytes_received;
struct sockaddr_in server_addr; struct sockaddr_in server_addr;
host = gethostbyname(url); /* 通过函数入口参数url获得host地址如果是域名会做域名解析 */
host = gethostbyname(url);
recv_data = rt_malloc(1024); /* 分配用于存放接收数据的缓冲 */
if (recv_data == RT_NULL) recv_data = rt_malloc(1024);
{ if (recv_data == RT_NULL)
rt_kprintf("No memory\n"); {
return; rt_kprintf("No memory\n");
} return;
}
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) /* 创建一个socket类型是SOCKET_STREAMTCP类型 */
{ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
rt_kprintf("Socket error\n"); {
/* 创建socket失败 */
rt_kprintf("Socket error\n");
/* release recv buffer */ /* 释放接收缓冲 */
rt_free(recv_data); rt_free(recv_data);
return; return;
} }
server_addr.sin_family = AF_INET; /* 初始化预连接的服务端地址 */
server_addr.sin_port = htons(port); server_addr.sin_family = AF_INET;
server_addr.sin_addr = *((struct in_addr *)host->h_addr); server_addr.sin_port = htons(port);
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero)); server_addr.sin_addr = *((struct in_addr *)host->h_addr);
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
if (connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) /* 连接到服务端 */
{ if (connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1)
rt_kprintf("Connect error\n"); {
/* 连接失败 */
rt_kprintf("Connect error\n");
/* release recv buffer */ /*释放接收缓冲 */
rt_free(recv_data); rt_free(recv_data);
return; return;
} }
while(1) while(1)
{ {
bytes_received = recv(sock, recv_data, 1024, 0); /* 从sock连接中接收最大1024字节数据 */
if (bytes_received < 0) bytes_received = recv(sock, recv_data, 1024, 0);
{ if (bytes_received < 0)
lwip_close(sock); {
/* 接收失败,关闭这个连接 */
lwip_close(sock);
/* release recv buffer */ /* 释放接收缓冲 */
rt_free(recv_data); rt_free(recv_data);
break; break;
} }
recv_data[bytes_received] = '\0'; /* 有接收到数据,把末端清零 */
recv_data[bytes_received] = '\0';
if (strcmp(recv_data , "q") == 0 || strcmp(recv_data , "Q") == 0) if (strcmp(recv_data , "q") == 0 || strcmp(recv_data , "Q") == 0)
{ {
lwip_close(sock); /* 如果是首字母是q或Q关闭这个连接 */
lwip_close(sock);
/* release recv buffer */ /* 释放接收缓冲 */
rt_free(recv_data); rt_free(recv_data);
break; break;
} }
else else
{ {
rt_kprintf("\nRecieved data = %s " , recv_data); /* 在控制终端显示收到的数据 */
} rt_kprintf("\nRecieved data = %s " , recv_data);
}
send(sock,send_data,strlen(send_data), 0); /* 发送数据到sock连接 */
} send(sock,send_data,strlen(send_data), 0);
}
return; return;
} }
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
#include <finsh.h> #include <finsh.h>
/* 输出tcpclient函数到finsh shell中 */
FINSH_FUNCTION_EXPORT(tcpclient, startup tcp client); FINSH_FUNCTION_EXPORT(tcpclient, startup tcp client);
#endif #endif

View File

@ -1,109 +1,122 @@
#include <rtthread.h> #include <rtthread.h>
#include <lwip/sockets.h> #include <lwip/sockets.h> /* 使用BSD Socket接口必须包含sockets.h这个头文件 */
static const char send_data[] = "This is TCP Server from RT-Thread."; static const char send_data[] = "This is TCP Server from RT-Thread."; /* 发送用到的数据 */
void tcpserv(void* parameter) void tcpserv(void* parameter)
{ {
char *recv_data; char *recv_data; /* 用于接收的指针,后面会做一次动态分配以请求可用内存 */
rt_uint32_t sin_size; rt_uint32_t sin_size;
int sock, connected, bytes_received; int sock, connected, bytes_received;
struct sockaddr_in server_addr, client_addr; struct sockaddr_in server_addr, client_addr;
rt_bool_t stop = RT_FALSE; rt_bool_t stop = RT_FALSE; /* 停止标志 */
recv_data = rt_malloc(1024); recv_data = rt_malloc(1024); /* 分配接收用的数据缓冲 */
if (recv_data == RT_NULL) if (recv_data == RT_NULL)
{ {
rt_kprintf("No memory\n"); rt_kprintf("No memory\n");
return; return;
} }
/* create a socket */ /* 一个socket在使用前需要预先创建出来指定SOCK_STREAM为TCP的socket */
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{ {
rt_kprintf("Socket error\n"); /* 创建失败的错误处理 */
rt_kprintf("Socket error\n");
/* release recv buffer */ /* 释放已分配的接收缓冲 */
rt_free(recv_data); rt_free(recv_data);
return; return;
} }
/* init server address */ /* 初始化服务端地址 */
server_addr.sin_family = AF_INET; server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000); server_addr.sin_port = htons(5000); /* 服务端工作的端口 */
server_addr.sin_addr.s_addr = INADDR_ANY; server_addr.sin_addr.s_addr = INADDR_ANY;
rt_memset(&(server_addr.sin_zero),8, sizeof(server_addr.sin_zero)); rt_memset(&(server_addr.sin_zero),8, sizeof(server_addr.sin_zero));
/* bind socket */ /* 绑定socket到服务端地址 */
if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1)
{ {
rt_kprintf("Unable to bind\n"); /* 绑定失败 */
rt_kprintf("Unable to bind\n");
/* release recv buffer */ /* 释放已分配的接收缓冲 */
rt_free(recv_data); rt_free(recv_data);
return; return;
} }
/* listen socket */ /* 在socket上进行监听 */
if (listen(sock, 5) == -1) if (listen(sock, 5) == -1)
{ {
rt_kprintf("Listen error\n"); rt_kprintf("Listen error\n");
/* release recv buffer */ /* release recv buffer */
rt_free(recv_data); rt_free(recv_data);
return; return;
} }
rt_kprintf("\nTCPServer Waiting for client on port 5000...\n"); rt_kprintf("\nTCPServer Waiting for client on port 5000...\n");
while(stop != RT_TRUE) while(stop != RT_TRUE)
{ {
sin_size = sizeof(struct sockaddr_in); sin_size = sizeof(struct sockaddr_in);
/* accept a client socket */ /* 接受一个客户端连接socket的请求这个函数调用是阻塞式的 */
connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size); connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size);
/* 返回的是连接成功的socket */
rt_kprintf("I got a connection from (%s , %d)\n", /* 接受返回的client_addr指向了客户端的地址信息 */
inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port)); rt_kprintf("I got a connection from (%s , %d)\n",
inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
while (1) /* 客户端连接的处理 */
{ while (1)
send(connected, send_data, strlen(send_data), 0); {
/* 发送数据到connected socket */
send(connected, send_data, strlen(send_data), 0);
bytes_received = recv(connected,recv_data, 1024, 0); /* 从connected socket中接收数据接收buffer是1024大小但并不一定能够收到1024大小的数据 */
if (bytes_received < 0) bytes_received = recv(connected,recv_data, 1024, 0);
{ if (bytes_received < 0)
/* close socket */ {
lwip_close(connected); /* 接收失败关闭这个connected socket */
break; lwip_close(connected);
} break;
}
recv_data[bytes_received] = '\0'; /* 有接收到数据,把末端清零 */
if (strcmp(recv_data , "q") == 0 || strcmp(recv_data , "Q") == 0) recv_data[bytes_received] = '\0';
{ if (strcmp(recv_data , "q") == 0 || strcmp(recv_data , "Q") == 0)
lwip_close(connected); {
break; /* 如果是首字母是q或Q关闭这个连接 */
} lwip_close(connected);
else if (strcmp(recv_data, "exit") == 0) break;
{ }
lwip_close(connected); else if (strcmp(recv_data, "exit") == 0)
stop = RT_TRUE; {
break; /* 如果接收的是exit则关闭整个服务端 */
} lwip_close(connected);
else stop = RT_TRUE;
{ break;
rt_kprintf("RECIEVED DATA = %s \n" , recv_data); }
} else
} {
} /* 在控制终端显示收到的数据 */
rt_kprintf("RECIEVED DATA = %s \n" , recv_data);
}
}
}
lwip_close(sock); /* 退出服务 */
lwip_close(sock);
/* release recv buffer */ /* 释放接收缓冲 */
rt_free(recv_data); rt_free(recv_data);
return ; return ;
} }
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
#include <finsh.h> #include <finsh.h>
/* 输出tcpserv函数到finsh shell中 */
FINSH_FUNCTION_EXPORT(tcpserv, startup tcp server); FINSH_FUNCTION_EXPORT(tcpserv, startup tcp server);
#endif #endif

View File

@ -1,42 +1,50 @@
#include <rtthread.h> #include <rtthread.h>
#include <lwip/netdb.h> #include <lwip/netdb.h> /* 为了解析主机名需要包含netdb.h头文件 */
#include <lwip/sockets.h> #include <lwip/sockets.h> /* 使用BSD socket需要包含sockets.h头文件 */
const char send_data[] = "This is UDP Client from RT-Thread.\n"; const char send_data[] = "This is UDP Client from RT-Thread.\n"; /* 发送用到的数据 */
void udpclient(const char* url, int port, int count) void udpclient(const char* url, int port, int count)
{ {
int sock; int sock;
struct hostent *host; struct hostent *host;
struct sockaddr_in server_addr; struct sockaddr_in server_addr;
host= (struct hostent *) gethostbyname(url); /* 通过函数入口参数url获得host地址如果是域名会做域名解析 */
host= (struct hostent *) gethostbyname(url);
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) /* 创建一个socket类型是SOCK_DGRAMUDP类型 */
{ if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
rt_kprintf("Socket error\n"); {
return; rt_kprintf("Socket error\n");
} return;
}
server_addr.sin_family = AF_INET; /* 初始化预连接的服务端地址 */
server_addr.sin_port = htons(port); server_addr.sin_family = AF_INET;
server_addr.sin_addr = *((struct in_addr *)host->h_addr); server_addr.sin_port = htons(port);
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero)); server_addr.sin_addr = *((struct in_addr *)host->h_addr);
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
while (count) /* 总计发送count次数据 */
{ while (count)
sendto(sock, send_data, strlen(send_data), 0, {
(struct sockaddr *)&server_addr, sizeof(struct sockaddr)); /* 发送数据到服务远端 */
sendto(sock, send_data, strlen(send_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
rt_thread_delay(50); /* 线程休眠一段时间 */
rt_thread_delay(50);
count --; /* 计数值减一 */
} count --;
}
/* close socket */ /* 关闭这个socket */
lwip_close(sock); lwip_close(sock);
} }
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
#include <finsh.h> #include <finsh.h>
/* 输出udpclient函数到finsh shell中 */
FINSH_FUNCTION_EXPORT(udpclient, startup udp client); FINSH_FUNCTION_EXPORT(udpclient, startup udp client);
#endif #endif

View File

@ -1,74 +1,84 @@
#include <rtthread.h> #include <rtthread.h>
#include <lwip/sockets.h> #include <lwip/sockets.h> /* 使用BSD socket需要包含sockets.h头文件 */
void udpserv(void* paramemter) void udpserv(void* paramemter)
{ {
int sock; int sock;
int bytes_read; int bytes_read;
char *recv_data; char *recv_data;
rt_uint32_t addr_len; rt_uint32_t addr_len;
struct sockaddr_in server_addr , client_addr; struct sockaddr_in server_addr, client_addr;
recv_data = rt_malloc(1024); /* 分配接收用的数据缓冲 */
if (recv_data == RT_NULL) recv_data = rt_malloc(1024);
{ if (recv_data == RT_NULL)
rt_kprintf("No memory\n"); {
return; /* 分配内存失败,返回 */
} rt_kprintf("No memory\n");
return;
}
/* create socket */ /* 创建一个socket类型是SOCK_DGRAMUDP类型 */
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{ {
rt_kprintf("Socket error\n"); rt_kprintf("Socket error\n");
/* release recv buffer */ /* 释放接收用的数据缓冲 */
rt_free(recv_data); rt_free(recv_data);
return; return;
} }
/* init server socket address */ /* 初始化服务端地址 */
server_addr.sin_family = AF_INET; server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000); server_addr.sin_port = htons(5000);
server_addr.sin_addr.s_addr = INADDR_ANY; server_addr.sin_addr.s_addr = INADDR_ANY;
rt_memset(&(server_addr.sin_zero),0, sizeof(server_addr.sin_zero)); rt_memset(&(server_addr.sin_zero),0, sizeof(server_addr.sin_zero));
if (bind(sock,(struct sockaddr *)&server_addr, /* 绑定socket到服务端地址 */
sizeof(struct sockaddr)) == -1) if (bind(sock,(struct sockaddr *)&server_addr,
{ sizeof(struct sockaddr)) == -1)
rt_kprintf("Bind error\n"); {
/* 绑定地址失败 */
rt_kprintf("Bind error\n");
/* release recv buffer */ /* 释放接收用的数据缓冲 */
rt_free(recv_data); rt_free(recv_data);
return; return;
} }
addr_len = sizeof(struct sockaddr); addr_len = sizeof(struct sockaddr);
rt_kprintf("UDPServer Waiting for client on port 5000...\n");
rt_kprintf("UDPServer Waiting for client on port 5000...\n"); while (1)
{
/* 从sock中收取最大1024字节数据 */
bytes_read = recvfrom(sock, recv_data, 1024, 0,
(struct sockaddr *)&client_addr, &addr_len);
/* UDP不同于TCP它基本不会出现收取的数据失败的情况除非设置了超时等待 */
while (1) recv_data[bytes_read] = '\0'; /* 把末端清零 */
{
bytes_read = recvfrom(sock, recv_data, 1024, 0,
(struct sockaddr *)&client_addr, &addr_len);
recv_data[bytes_read] = '\0';
rt_kprintf("\n(%s , %d) said : ",inet_ntoa(client_addr.sin_addr),
ntohs(client_addr.sin_port));
rt_kprintf("%s", recv_data);
if (strcmp(recv_data, "exit") == 0) /* 输出接收的数据 */
{ rt_kprintf("\n(%s , %d) said : ",inet_ntoa(client_addr.sin_addr),
lwip_close(sock); ntohs(client_addr.sin_port));
rt_kprintf("%s", recv_data);
/* release recv buffer */ /* 如果接收数据是exit退出 */
rt_free(recv_data); if (strcmp(recv_data, "exit") == 0)
break; {
} lwip_close(sock);
}
return; /* 释放接收用的数据缓冲 */
rt_free(recv_data);
break;
}
}
return;
} }
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
#include <finsh.h> #include <finsh.h>
/* 输出udpserv函数到finsh shell中 */
FINSH_FUNCTION_EXPORT(udpserv, startup udp server); FINSH_FUNCTION_EXPORT(udpserv, startup udp server);
#endif #endif