3.TCP回响服务器实现及源码分析上

1.tcp_echoserver.c 移植

文件目录

C:\Users\Think\STM32Cube\Repository\STM32Cube_FW_F4_V1.24.1\Projects\STM324xG_EVAL\Applications\LwIP\LwIP_TCP_Echo_Server\Src

地址是本机的,端口号是7

2.实验分析

1.移植tcp_echoserver.c文件

2.main.c添加tcp_echoserver_init

3.编译烧写

4.使用NC命令进行连接

5.发送任意数据等待回响

3.tcp_echoserver 业务分析

复制代码
static struct tcp_pcb *tcp_echoserver_pcb;

/* ECHO protocol states */
enum tcp_echoserver_states
{
  ES_NONE = 0,
  ES_ACCEPTED,
  ES_RECEIVED,
  ES_CLOSING
};

/* structure for maintaing connection infos to be passed as argument 
   to LwIP callbacks*/
struct tcp_echoserver_struct
{
  u8_t state;             /* current connection state */
  u8_t retries;
  struct tcp_pcb *pcb;    /* pointer on the current tcp_pcb */
  struct pbuf *p;         /* pointer on the received/to be transmitted pbuf */
};

void tcp_echoserver_init(void);
static err_t tcp_echoserver_accept(void *arg, struct tcp_pcb *newpcb, err_t err);
static err_t tcp_echoserver_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
static void tcp_echoserver_error(void *arg, err_t err);
static err_t tcp_echoserver_poll(void *arg, struct tcp_pcb *tpcb);
static err_t tcp_echoserver_sent(void *arg, struct tcp_pcb *tpcb, u16_t len);
static void tcp_echoserver_send(struct tcp_pcb *tpcb, struct tcp_echoserver_struct *es);
static void tcp_echoserver_connection_close(struct tcp_pcb *tpcb, struct tcp_echoserver_struct *es);
相关推荐
都在酒里4 分钟前
STM32 板卡产测:烧录、序列号、校准与留档
stm32·单片机·嵌入式硬件
蓝天居士2 小时前
JY61P认识、学习与实战(19)—— STM32F405RGT6与JY61P通信(4)
stm32·jy61p
fruge3 小时前
ClipSketch AI视频转手绘故事板实战:关键帧选取、Gemini绘图与文案生成
网络·网络协议·http
意法半导体STM324 小时前
【官方原创】初识STM32CubeCLI:基于命令行的STM32工具链
stm32·单片机·stm32cubeide·stm32cubeclt·stm32工具链
BT-BOX6 小时前
基于STM32的锂电池充电监测电路Proteus仿真设计介绍
stm32·嵌入式硬件·proteus
jianqiang.xue7 小时前
开了 -O2 延时函数全乱:volatile 救不了空循环
人工智能·单片机·嵌入式硬件·json·嵌入式·ai编程·代码审查
橘为己有4417 小时前
STM32:WS2812B_PWM_DMA实战
stm32·单片机·嵌入式硬件
蔚蓝忧郁8 小时前
使用 matter-dissector 抓包解析 Matter 协议报文
网络协议
Zw-awa8 小时前
常见通信怎么选:UART、I2C、SPI、CAN 与 USB 到底怎么选
stm32
ss27310 小时前
FastAPI WebSocket 入门:双向通信、连接管理与广播实践;一条长连接如何撑起实时应用
websocket·网络协议·fastapi