欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 名人名企 > 3.TCP回响服务器实现及源码分析上

3.TCP回响服务器实现及源码分析上

2025/6/18 15:38:14 来源:https://blog.csdn.net/a2123827797/article/details/148672283  浏览:    关键词: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);

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词