当前位置:网站首页>LwIP development | socket | UDP
LwIP development | socket | UDP
2022-07-28 16:31:00 【Chop Hua】
** Reference resources :**https://blog.csdn.net/Chuangke_Andy/article/details/113116289
** significance :** Improve each platform lwip TCP/UDP Programming compatibility , Portability
Environmental Science :
1.freertos
2. Turn on LWIP_SOCKET
3. Bgi, HC32F4A0( Compatible )
Code programming
#if LWIP_SOCKET
/******socket_udp_server.c******/
#include "lwip/opt.h"
#include <lwip/sockets.h>
#include "lwip/sys.h"
#include "lwip/api.h"
#include "string.h"
#define SERVER_PORT (6666UL)
#define BUFF_SIZE (1024UL)
static char ReadBuff[BUFF_SIZE];
void vUdpServerTask(void){
int sockfd, n, i;
struct sockaddr_in server_addr, client_addr;
socklen_t client_addr_len;
// Create packet socket (UDP)
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
// Fill in address information
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(SERVER_PORT);
server_addr.sin_addr.s_addr = htonl(INADDR_ANY); // In itself IP
// binding socket
bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr));
client_addr_len = sizeof(client_addr);
while(1){
// Waiting for the client to send data
n = recvfrom(sockfd,ReadBuff,BUFF_SIZE,0,(struct sockaddr *)&client_addr, &client_addr_len);
// Write back to the client
write(sockfd,ReadBuff,n);
}
}
#endif
边栏推荐
- 学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
- PHP mb_substr 中文乱码
- 魏建军骑宝马也追不上李书福
- 头条文章_signature
- Paging query in applet
- 微信公众号获取素材列表
- C language exception handling mechanism: jump function jump function setjmp/sigsetjmp and longjmp/siglongjmp
- PHP 图片上传
- 排序3-选择排序与归并排序(递归实现+非递归实现)
- What does it remote operation and maintenance mean? Which is the best remote operation and maintenance software?
猜你喜欢

HyperMesh自动保存(增强版)插件使用说明

ANSA二次开发 - 抽中面的两种方法

mysql查询 limit 1000,10 和limit 10 速度一样快吗?如果我要分页,我该怎么办?

CoDeSys realizes bubble sorting

What does it remote operation and maintenance mean? Which is the best remote operation and maintenance software?

Kubeedge releases white paper on cloud native edge computing threat model and security protection technology

栈的介绍与实现(详解)

排序3-选择排序与归并排序(递归实现+非递归实现)

一大早支付宝来短信说你中“奖”了?处理服务器挖矿病毒 - kthreaddi

Redis series 4: sentinel (sentinel mode) with high availability
随机推荐
About standard IO buffers
Headline article_ signature
QT packaging
Geodetic coordinate system to Martian coordinate system
Zhengda cup hacker marathon data analysis competition
LeetCode-学会对无序链表进行插入排序(详解)
大地坐标系转换火星坐标系
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
在vs code上配置Hypermesh二次开发环境
ANSA二次开发 - 在PyCharm上搭建ANSA/META二次开发环境
About the web docking pin printer, lodop uses
el-input限制只能输入规定的数
HyperMesh自动保存(增强版)插件使用说明
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
PHP image synthesis technology
2021 Yahong pen test questions
5 亿用户,比微信还早四年……这个运营了 15 年的 APP 即将永久停服
Wechat official account to obtain material list
LwIP development | socket | DNS domain name resolution
“蔚来杯“2022牛客暑期多校训练营3 ACFHJ