|
楼主 |
发表于 2011-7-13 16:42:24
|
显示全部楼层
回复【3楼】ffxz
-----------------------------------------------------------------------
好的,晚上我按您的意思修改。
开发环境:LPC1768开发板、用的1768内置以太网控制器。
出现故障后服务器应答非TCP数据包,PING的时间由1毫秒变成几秒响应。
这是我用WEB服务器改的TCP服务器
void http_server(void *pdata)
{
struct netconn *conn, *newconn;
u8_t err;
u16_t buflen,rexmit_len;
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, NULL, 502); // 设绑定端口 原80
netconn_listen(conn); // 侦听
while (1)
{
newconn = netconn_accept(conn); /* Grab new connection. */
if(newconn != NULL) /* Process the new connection. */
{
struct netbuf *buf;
void *data;
u16_t len;
while((buf = netconn_recv(newconn)) != NULL)
{
do
{
netbuf_data(buf, &data, &len);
memcpy(appbuf, buf->ptr->payload, len);
rexmit_len = prt_app_proc(TxBuf1, appbuf, buflen); // 应用规约解析调用
err = netconn_write(newconn, TxBuf1, rexmit_len, NETCONN_COPY); // 应用应答
if(err != ERR_OK)
{
/*printf("tcpecho: netconn_write: error \"%s\"\n", lwip_strerr(err));*/
}
}while(netbuf_next(buf) >= 0);
netbuf_delete(buf);
}
//netbuf_delete(buf); // 如此处,TCP不回应客户机
netconn_close(newconn);
}
}
} |
|