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);
相关推荐
剑锋所指,所向披靡!7 分钟前
TCP并发服务器
服务器·网络·tcp/ip
AI备忘录1 小时前
(十一)DHCP 配置命令五厂商对照:华为 华三 锐捷 迈普 思科
服务器·网络·网络协议·网络安全·华为
捷瑞电子工坊10 小时前
FreeRTOS任务管理:从入门到实践(标准库版)
stm32·嵌入式·freertos·实时操作系统·任务管理·标准外设库·任务挂起与恢复
暴力求解11 小时前
Linux网络---传输层协议TCP(二)
linux·服务器·开发语言·网络·tcp/ip
游戏开发爱好者812 小时前
WebSocket 抓包怎么查看内容?从握手到消息帧完整解读
网络协议·计算机网络·网络安全·ios·adb·https·udp
80s77713 小时前
动态ip和静态ip有什么区别
服务器·网络·tcp/ip
尘世壹俗人14 小时前
如何生成SSL要用的自签证书
网络协议
ye1501277745516 小时前
12V转3V-5V2A电位器无极调光调速WT7027
stm32·单片机·嵌入式硬件
无损检测小白白17 小时前
STM32F407 串口3 DMA收发-标准库
stm32·单片机·嵌入式硬件
新手unity自用笔记18 小时前
unity基于Socket的网络学习
网络·网络协议·学习·unity·c#·游戏引擎