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);
相关推荐
Y Shy13 小时前
2026.10 在受限的嵌入式机器人设备中使用LLM Agent
机器人·llm·嵌入式·agent
铅笔小新z14 小时前
【stm32】IWDG(独立看门狗)
stm32·单片机·嵌入式硬件
无敌贵点大王15 小时前
从寄存器层面重学STM32(2)——RCC和时钟树
stm32·单片机·嵌入式硬件
用户7661660031118 小时前
先中转、后打洞:libnpf 的 NAT 穿透与对称型 NAT 实战
嵌入式
mister_guo18 小时前
HTTP 和 RPC:从一次干饭说清它们的区别
网络协议·http·rpc
优信电子18 小时前
HC05蓝牙模块主机与从机进行连接通信
单片机·物联网·嵌入式
K成长日志18 小时前
BLE Host层L2CAP -- 配置参数选项
物联网·网络协议·嵌入式·蓝牙·iot·ble·bluetooth
深圳老胡19 小时前
STM32CubeMX 2 与 STM32CubeMX 的主要区别
笔记·stm32·单片机·代码规范
゛凌乱的记忆づ20 小时前
50元从零到成品:一套AI辅助的嵌入式实战入门教程——IIC篇
人工智能·stm32·单片机·嵌入式硬件
幻智星科技20 小时前
纯FPGA网络通信实现微秒级确定性延迟
网络协议·fpga开发·硬件架构