大神,小弟现在使用uip连接两个服务器(ip地址和端口号不相同)。现在状况百出:1,不能断开服务端一,后面发送给服务器二的发送给服务器一了;2,断开连接一了,马上重新连接服务器一和服务器二,但数据是还是发送给服务器一,3,断开了服务器一,连接服务器二至少有三遍,且不能发送数据。
下面是部分代码,大神能帮我看一下么?看一下是哪里出错了,能不能提供一些建议。谢谢大家了。
重新连接的代码:
[mw_shl_code=c,true]void tcp_client_reconnect(void)
{
uip_ipaddr_t ipaddr;
uip_ipaddr(&ipaddr,10,10,58,63);
uip_connect(&ipaddr,htons(m_port));
}[/mw_shl_code]
[mw_shl_code=c,true]switch(_state)
{
case state1:
{
_state=state01;delay_ms(300);
uip_SendCheck();
break;
}
case state2:
{
_state=state01;delay_ms(300);
uip_Get_Config();
break;
}
default:
break;
}[/mw_shl_code]
[mw_shl_code=c,true]void uip_SendCheck(void)
{
while (1)
{
u8 KEY;
KEY_Scan(0);
uip_polling();
POINT_COLOR=GBLUE;BACK_COLOR=LGRAY;
if(tcp_client_tsta!=tcp_client_sta)
{
if(tcp_client_sta&(1<<6))
{
if(_state==state02)
{
POINT_COLOR=BROWN;BACK_COLOR=WHITE;
if (tcp_client_databuf[4]=='0'&&tcp_client_databuf[5]=='0')
{
STM32_GUI_2();
Show_Str(2,2,100,12,(u8*)c1,12,0);
Show_Str(110,2,80,12,(u8*)c2,12,0);
Show_Str(180,2,80,12,(u8*)c3,12,0);
LCD_ShowString(2,18,200,12,12,(u8*)num5);[/mw_shl_code]
[mw_shl_code=c,true] _state = state2; tcp_client_sta&=~(1<<6); [/mw_shl_code]
[mw_shl_code=c,true] tcp_client_sta&=~(1<<7);
delay_ms(300);break;
}
else if(tcp_client_databuf[4]=='1'&&tcp_client_databuf[5]=='1')
{
LCD_ShowString(2,18,220,12,12,"ERROR!!!");
}
tcp_client_sta&=~(1<<6);
}
}
tcp_client_tsta=tcp_client_sta;
}
if(_state==state01)
{
if(tcp_client_sta&(1<<7))
{
while(2)
{
if(USART2_RX_STA&0X8000)
{
memcpy(num5,(char*)USART2_RX_BUF,strlen((char*)USART2_RX_BUF));
sprintf((char*)tcp_client_databuf,"%%SP%%C^101^^^0^SN_%s^^^^N90%%+%%",num5);
USART2_RX_STA=0;break;
}
}
strcmp((char*)tcp_client_databuf,(char*)tcp_client_databuf);
tcp_client_sta|=1<<5;delay_ms(100);
_state=state02;
}
delay_ms(300);
}
}
}[/mw_shl_code]
[mw_shl_code=c,true]void uip_Get_Config(void)
{
DIR Folder; FIL file;
m_port = 6969;
tcp_client_reconnect(); while(2)
{
uip_polling();
if(tcp_client_tsta!=tcp_client_sta)[/mw_shl_code]
[mw_shl_code=c,true] {
if(tcp_client_sta&(1<<7))LCD_ShowString(160,307,200,12,12,"Connected2!");
else LCD_ShowString(160,307,200,12,12,"Connecting2!");
if(tcp_client_sta&(1<<6))[/mw_shl_code]
[mw_shl_code=c,true] {
if(_state==state02)
{
f_mkdir("/config");res=f_opendir(&Folder,"/config");[/mw_shl_code]
[mw_shl_code=c,true] res=f_open(&file,"/config/50H90.TXT", FA_OPEN_ALWAYS | FA_WRITE | FA_READ );[/mw_shl_code]
[mw_shl_code=c,true] f_lseek(&file,f_size(&file));
res=f_write(&file,tcp_client_databuf,strlen((char*)tcp_client_databuf),&br);
delay_ms(100);
f_close(&file);
if(tcp_client_databuf[1]=='O' & tcp_client_databuf[2]=='K')
{
_state = state4;
break;
}
}
tcp_client_sta&=~(1<<6);[/mw_shl_code]
[mw_shl_code=c,true] }
tcp_client_tsta=tcp_client_sta;
}
if(_state == state01)
{
if(tcp_client_sta&(1<<7))[/mw_shl_code]
[mw_shl_code=c,true] {
memset(tcp_client_databuf,0x00,sizeof((u8*)tcp_client_databuf));
strcpy((char*)tcp_client_databuf,"00000017^getconfig^|50H90");
printf("tcp_client_databuf = %s",tcp_client_databuf);
tcp_client_sta|=1<<5; delay_ms(300);
_state = state02;
}
delay_ms(100);
} [/mw_shl_code]
[mw_shl_code=c,true] }
}[/mw_shl_code]
大神们,麻烦帮我看一下,如果你们有做过类似的,方便的情况下可不可以让我参考一下。谢谢啦,这个比较急。麻烦你们了。
一周热门 更多>