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);
相关推荐
许愿OvO1 小时前
IP--MGER综合实验报告
网络·tcp/ip·智能路由器
小刘|2 小时前
Https以及CA证书
网络·网络协议·https
筑梦之月4 小时前
如何查看电脑后门IP和流量?
网络协议·tcp/ip·电脑
knight_20245 小时前
嵌入式学习日志————对射式红外传感器计次
stm32·单片机·嵌入式硬件·学习
Ronin-Lotus6 小时前
嵌入式硬件篇---ESP32拓展板
stm32·单片机·嵌入式硬件
林深的林10 小时前
Http证书体系及证书加密流程(通信流程)
网络协议·http·https
邹诗钰-电子信息工程13 小时前
bmp280的压力数据采集(i2c设备驱动+设备树编写)
stm32·单片机·嵌入式硬件
7ACE16 小时前
Wireshark TS | 发送数据超出接收窗口
网络协议·tcp/ip·wireshark
先知后行。16 小时前
网络协议HTTP、TCP(草稿)
网络·网络协议