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);
相关推荐
π同学19 分钟前
基于RT-Thread的STM32开发第十一讲——编码器模式
stm32·rt_thread·双相编码器
汤愈韬3 小时前
双向NAT
网络·网络协议·网络安全·security·huawei
*才华有限公司*3 小时前
RTSP视频流播放系统
java·git·websocket·网络协议·信息与通信
栗子叶3 小时前
IP协议 地址划分&MAC地址作用&ip addr命令
网络·tcp/ip·macos
一路往蓝-Anbo5 小时前
第五篇:硬件接口的生死劫 —— GPIO 唤醒与测量陷阱
c语言·驱动开发·stm32·单片机·嵌入式硬件
Filotimo_7 小时前
桥接服务概念
网络协议·网络安全·信息与通信
镜中人★7 小时前
408计算机网络考纲知识点(更新中)
网络·网络协议·计算机网络
xflySnail7 小时前
nas服务域名高速访问-获取公网IP和端口
网络·tcp/ip·智能路由器
Y1rong7 小时前
STM32之时钟
stm32·单片机·嵌入式硬件
禾叙_8 小时前
【netty】Netty之TCP链接
网络·网络协议·tcp/ip