#include "stm32_config.h"

void main_Client_task(void *pdata)
{	
	u8 buff[200]="";
	u32 len = 0;
	u8 num = 0;
	u8 err = 0;
	
	while(1)
	{
		while(!TcpClient_Link) //如果连接上服务器了，TcpClient_Link会被置1
		{
			printf("tcp_echoclient_connect...\r\n");
			tcp_echoclient_connect();
			delay_ms(1000);				
		}
		while(TcpClient_Link)
		{
			len = TCP_Client_Recv(buff, sizeof(buff));
			if(len)
			{
				printf("Client:[%d][%s]\r\n", len,buff);
				len = 0;
			}
		
			if(num++>=100) //隔一段时间发送个“Client ok”数据给服务器
			{
				num = 0;
				if(-1 == TCP_Client_Send("Client ok\r\n", strlen("Client ok\r\n")))
				{
					printf("Send Data Error.\r\n");
					if(err++ >= 1)
					{
						err = 3;
						tcp_client_close();
					}
				}
				else
				{
					err = 0;
					printf("Send Data OK.\r\n");
				}
				memset(buff, 0, sizeof(buff));
				len = 0;		
			}
			delay_ms(10);
		}
	}
}



