当前位置:网站首页>LwIP development | socket | DNS domain name resolution
LwIP development | socket | DNS domain name resolution
2022-07-28 16:21: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
#include "tcp_client_test.h"
#include "lwip/opt.h"
#include <lwip/sockets.h>
#include "lwip/sys.h"
#include "lwip/api.h"
#include "string.h"
#if LWIP_SOCKET
#define DEST_PORT 6134// Destination address port number
#define DEST_IP "192.168.2.195"/* Destination address IP, This is set as local */
#define MAX_DATA 1024// The maximum amount of data received
#define LWIP_TCP_DEBUG_ENABLE 1
#if LWIP_TCP_DEBUG_ENABLE
#define LWIP_TCP_DEBUG printf
#else
#define LWIP_TCP_DEBUG(...)
#endif
void tcp_client_thread(void)
{
int sockfd,new_fd;/*cocket Handle and handle after receiving connection */
struct sockaddr_in dest_addr;/* Destination address information */
char buf[MAX_DATA];// Store received data
sockfd=socket(AF_INET,SOCK_STREAM,0);/* establish socket*/
if(sockfd < 0)
{
LWIP_TCP_DEBUG("socket failed:%d",errno);
}
dest_addr.sin_family=AF_INET;
dest_addr.sin_port=htons(DEST_PORT);
dest_addr.sin_addr.s_addr=inet_addr(DEST_IP);
inet_aton(DEST_IP,&dest_addr.sin_addr);/* Convert the dotted decimal system to 32 Bit integer type */
if(connect(sockfd,(struct sockaddr*)&dest_addr,sizeof(struct sockaddr)) == -1){
// Connection method , Incoming handle , Destination address and size
LWIP_TCP_DEBUG("connect failed:%d",errno);// In case of failure, you can print errno
}
else
{
LWIP_TCP_DEBUG("connect success");
recv(sockfd,buf,MAX_DATA,0);// Enter the received data into buf, The parameters are handles , Storage place , Maximum length , Other information ( Set to 0 that will do ).
LWIP_TCP_DEBUG("Received:%s",buf);
}
close(sockfd);// close socket
return;
}
#endif
边栏推荐
- 关于标准IO缓冲区的问题
- 2021 肯特面试题3
- 软件问题修复跟踪系统实战开发教程(上篇)
- 分体式测斜探头安装要点及注意事项
- 加速投资的小红书,“病急乱投医”?
- laravel
- JS linked list 02
- RF module wireless transceiver rf63u chip application data transmission and infrastructure network
- Ethernet to RS485 serial port counter WiFi module LED light controller ibf165
- Rust Getting Started Guide (crite Management)
猜你喜欢

The deep displacement monitoring system wk813 is used to measure the deep displacement of slopes, dams, embankments, railways and building foundation pit excavation

KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书

Common problems and precautions of remote serial port server (adapter) uart/i2c/1-wire/spi PS304

JS linked list 02

分体式测斜探头安装要点及注意事项

Vm501 development kit development version single vibrating wire sensor acquisition module geotechnical engineering monitoring

激光测距仪非接触式地表裂缝监测仪

Roson的Qt之旅#101 Qt Quick中的模型和视图

JS linked list 01

RF module wireless transceiver rf63u chip application data transmission and infrastructure network
随机推荐
VM501开发套件开发版单振弦式传感器采集模块岩土工程监测
Note: numerical accumulation animation
MicTR01 Tester 开发套件(振弦采集读数仪)使用说明
Duty cycle switch output high speed pulse counter rtumodbus module ibf63
Food safety | these two kinds of melons and fruits should be improved, especially for pregnant women with constipation
Installation points and precautions of split angle probe
5 亿用户,比微信还早四年……这个运营了 15 年的 APP 即将永久停服
2.855 billion yuan! Qingdao Xinen completed the capital increase: Xingcheng Jidian became the largest shareholder, holding 57.10%
带你来浅聊一下!单商户功能模块汇总
小程序中的分页查询
How to quickly access the unified authentication system
Shell programming specifications and variables
2021-10-21 notes
资本「断供」两年,我只能把公司卖了
食品安全 | 这两类瓜果宜改善便秘 孕妇人群尤其建议
Roson的Qt之旅#102 ListModel
A tour of grp:05 - GRP server streaming service end stream
Brief tutorial for soft exam system architecture designer | software debugging
Advantages of optical rain gauge over tipping bucket rain gauge
JS bidirectional linked list 01