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);
相关推荐
xxtzaaa4 分钟前
抖音私密账号显示IP属地吗?能更改IP么?
网络·网络协议·tcp/ip
张人玉9 小时前
C# TCP 服务端开发笔记(TcpListener/TcpClient)
stm32·单片机·嵌入式硬件
宁静致远20219 小时前
FreeRTOS任务同步与通信--事件标志组
stm32·嵌入式·freertos
宁静致远202110 小时前
仿照STM32 HAL库设计思想使用FreeRTOS实现异步非阻塞式设备驱动
stm32·嵌入式硬件
未来之窗软件服务12 小时前
操作系统应用开发(二十五)RustDesk 502错误—东方仙盟筑基期
网络协议·远程桌面·仙盟创梦ide·东方仙盟·rustdek
田甲13 小时前
【STM32】墨水屏驱动开发
stm32·单片机·墨水屏
苜蓿草茸茸15 小时前
HTTP 协议详解
网络协议·http
飞天巨兽17 小时前
HTTP基础教程详解
前端·网络·网络协议·http
dot to one17 小时前
应用层:Http、Https
linux·c++·网络协议
沐欣工作室_lvyiyi18 小时前
采用AIOT技术的防疫物资监控系统的设计与开发(论文+源码)
stm32·单片机·嵌入式硬件·毕业设计·防疫物资