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);
相关推荐
Jerry丶Li1 小时前
二十三、STM32的ADC(三)(ADC多通道)
stm32·单片机·嵌入式硬件
d111111111d2 小时前
STM32外设学习--TIM定时器--编码器接口(程序)
笔记·stm32·嵌入式硬件·学习
辰哥单片机设计2 小时前
STM32项目分享:水质检测系统(升级版)
stm32·单片机·嵌入式硬件
小李独爱秋2 小时前
计算机网络经典问题透视:什么是NAPT?它有哪些特点?
网络·网络协议·计算机网络·网络安全·智能路由器
Evan_ZGYF丶2 小时前
深入解析CFS虚拟运行时间:Linux公平调度的核心引擎
linux·驱动开发·嵌入式·bsp
wukan8883 小时前
【SMTP】在线配置测试工具,如何配置接口?
git·网络协议·编辑器
straw_hat.5 小时前
32HAL——RTC时钟
stm32·学习
铭哥的编程日记6 小时前
【Linux网络】传输层协议TCP
linux·网络·tcp/ip
教练、我想打篮球7 小时前
29 ip查询工具 并发送邮件通知目标用户
tcp/ip·ip·query
大聪明-PLUS7 小时前
Linux 上的 GitOps:使用 Git 进行无缝基础设施管理
linux·嵌入式·arm·smarc