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);
相关推荐
疯狂打码的少年2 分钟前
【计算机网络】TCP/IP协议族(四层体系结构,与OSI对比)
网络·笔记·tcp/ip·计算机网络
布莱克60539 分钟前
TCP 三次握手与四次挥手详解
服务器·网络·tcp/ip·计算机网络·网络编程
糖糖单片机设计2 小时前
基于 STM32 的小型鸟类宠物繁殖系统
stm32·嵌入式硬件·宠物
阿钱真强道3 小时前
01 嵌入式操作系统 | 课程导论与虚拟机安装 Ubuntu
linux·ubuntu·嵌入式·虚拟机
严谨的麻辣烫4 小时前
AI Agent为什么越来越需要固定出口IP?从API白名单到生产环境网络管理
服务器·网络·tcp/ip·代理服务器
企业通信技术笔记4 小时前
企业IM内外网隔离部署:DNS、证书、WebSocket与跨网接口设计
websocket·网络协议·架构·php·信息与通信
captain3764 小时前
TCP网络编程:ServerSocket与Socket详解
服务器·网络·tcp/ip
流烟默6 小时前
HTTP 连接管理技术梳理:JDK KeepAliveCache 机制与池化选型
java·网络协议·http
单片机仿真设计6 小时前
【proteus仿真】基于 STM32 单片机电梯运行状态监控设计(仿真图+程序)
stm32·单片机·嵌入式硬件·proteus
Java小白笔记7 小时前
FlClash TUN 栈模式选择与验证指南
网络·网络协议