⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpserver.c

📁 ucos移植到44b0
💻 C
字号:
#ifndef  _TCP_SERVER_C
#define  _TCP_SERVER_C
#include "includes.h"
/*
 * Author hugang <hgxxx@51eda.com>
 */
#include "lwip/api.h"
#include "target.h"
#include <stdio.h>
#include <string.h>

extern void handleConnection(struct netconn * newconn);
extern void initData(void);
void tcp_server_thread(void *arg)
{
	struct netconn *conn, *newconn;
	struct ip_addr l_ip;
	err_t err;
	char strbuf[64], cmdbuf[30];
	u16_t strLen;
	s8_t cmd_c;
    #if 0
    char pagebuf[500];
    const char *page=
    {"HTTP/1.1 200 OK\nConetent-Type: text/html\n\n"
       "<HTML><HEAD><TITLE>W</TITLE></HEAD>"
       "<BODY><H1>W</H1><P>"
       "%d<P>"
       "<FORM ACTION=\"/control\" METHOD= \"POST\">"
              "<INPUT TYPE=TEXT NAME=\"TEST1\" SIZE=10>Test1:" 
              "<INPUT TYPE=TEXT NAME=\"TEST2\" SIZE=10>Test2:"
              "<INPUT TYPE=TEXT NAME=\"TEST3\" SIZE=10>Test3:"
              "<INPUT TYPE=\"submit\" NAME=\"Go\">"
       "</FORM></BODY></HTML>\n"
    };

    memcpy(pagebuf,page,500);
    #endif
    initData();
	IP4_ADDR(&l_ip, 192,168,0,100);
  	/* Create a new connection identifier. */
	conn = netconn_new(NETCONN_TCP);

	netconn_bind(conn, &l_ip, 80);

  	/* Tell connection to go into listening mode. */
	netconn_listen(conn);

	while(1)
	{
		newconn = netconn_accept(conn);
		//strlen = sprintf(strbuf,"Welcome to TCP datatime server \r\n");
		//netconn_write(newconn, strbuf, strlen, NETCONN_COPY);

		/* Process the new connection. */
        #if 0
		if(newconn != NULL)
		{
	  		struct netbuf *buf;
	  		void *data;
	  		u16_t len;
			u8_t *datab;

            while((buf = netconn_recv(newconn)) != NULL)
			{
				do
				{
					netbuf_data(buf, &data, &len);
					datab = (unsigned char *) data;
					if(*datab != 0x39)
					{
					    INT32U os_time;
        				os_time = OSTimeGet();
        				//strlen = sprintf(strbuf, "\r\nNow, OS time is: %d", os_time);
        				//strlen = sprintf(pagebuf, "", page);
        				//netconn_write(newconn, strbuf, strlen, NETCONN_COPY);	
        				memset(pagebuf,0x00,500);
        				strLen = sprintf(pagebuf,page,os_time);
        				netconn_write(newconn, pagebuf, strLen, NETCONN_COPY);	
                        netbuf_delete(buf);
                        goto t_exit;
					}
                    else
                    {
                        netbuf_delete(buf);
						goto t_exit;                    
                    }                        
				}
				while(netbuf_next(buf) >= 0);
				netbuf_delete(buf);
	  		}	
            
		}
        #endif
        if(newconn != NULL)
		{
           handleConnection(newconn);
t_exit:
		   err = netconn_delete(newconn);
        }
	
  	}
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -