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);
相关推荐
forAllforMe13 分钟前
LAN9252 从机模式寄存器的配置代码示例
stm32·单片机·嵌入式硬件
huohaiyu37 分钟前
HTTPS的加密流程
网络协议·http·https
源远流长jerry38 分钟前
RDMA 传输服务详解:可靠性与连接模式的深度剖析
linux·运维·网络·tcp/ip·架构
花月C1 小时前
基于WebSocket的 “聊天” 业务设计与实战指南
java·网络·后端·websocket·网络协议
guygg882 小时前
基于STM32的贪吃蛇游戏实现(OLED屏)
stm32·嵌入式硬件·游戏
BackCatK Chen2 小时前
STM32保姆级入门教程|第4章:GPIO输入+外部中断 实现按键控制LED(手把手全流程)
stm32·单片机·外部中断·按键控制 led·stm32cubeid·gpio 输入
嵌入式-老费2 小时前
vivado hls的应用(带ddr读取的ip)
服务器·网络·tcp/ip
Barkamin2 小时前
HTTPS的工作过程
网络协议·http·https
小鱼不会骑车3 小时前
TCP 核心知识精讲:是什么 · 为什么 · 怎么做
网络·网络协议·tcp/ip
szxinmai主板定制专家3 小时前
基于 STM32 + FPGA 船舶电站控制器设计与实现
arm开发·人工智能·stm32·嵌入式硬件·fpga开发·架构