当前位置:网站首页>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
边栏推荐
- A tour of grp:05 - GRP server streaming service end stream
- Image semantic segmentation practice: tensorflow deeplobv3+ train your own dataset
- [Multisim Simulation] LM339 zero crossing circuit simulation
- 便携式钻孔测斜仪数据采集仪测量原理与测斜探头的连接及使用方法
- 5 亿用户,比微信还早四年……这个运营了 15 年的 APP 即将永久停服
- Laser rangefinder non-contact surface crack monitor
- Food safety | these two kinds of melons and fruits should be improved, especially for pregnant women with constipation
- js中的for循环总结
- Shell编程规范与变量
- Duty cycle switch output high speed pulse counter rtumodbus module ibf63
猜你喜欢

软件问题修复跟踪系统实战开发教程(上篇)

Multifunctional mixed signal AI acquisition / switching value di/do acquisition to rs485/232/modbus module

Ask if you don't understand, and quickly become an advanced player of container service!

js 双向链表 01

射频模块无线收发RF63U芯片应用数据传输和基建网络

Two special functions (arrow function and method)

JS array (summary)

Advantages of optical rain gauge over tipping bucket rain gauge

深部位移监测系统wk813应用边坡、大坝、堤防、铁路和建筑基坑开挖等深部位移测量

头条文章_signature
随机推荐
VM501开发套件开发版单振弦式传感器采集模块岩土工程监测
R language ggplot2 visually draws line plots, and uses gghighlight package to highlight the lines that meet the combination judgment conditions in the line graphs (satisfies both condition a and b)
Instructions for mictr01 Tester development kit (vibrating wire acquisition reader)
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
Notes on October 22, 2021
2021 Yahong pen test question 2
Using SYSTEMd to manage services
太阳能路灯的根本结构及作业原理
R language uses ggpairs function of ggally package to visualize pairwise relationship graph of grouping multivariable, set alpha parameter to change image transparency, diagonal continuous variable de
Temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
Redis series 4: sentinel (sentinel mode) with high availability
Why do most people who learn programming go to Shenzhen and Beijing?
Note: the value is rounded up to ten, hundred, thousand, ten thousand
解决电脑恶意广告弹窗的思路
RF module wireless transceiver rf63u chip application data transmission and infrastructure network
Note: numerical accumulation animation
PHP mb_substr 中文乱码
MicTR01 Tester 开发套件(振弦采集读数仪)使用说明
JS linked list 01
Record Clearfix clear float