跪求uip1.0作为客户端主动连接服务器的例子
手头上有个enc28j60的模块,移植uip1.0作为服务器与pc机通讯正常,现在按照其它高手说的一步一步改成服务端模式,能ping通,怎么也无法主动连上服务器.整了好些时间,要崩溃了.我的是ATMEGA128+enc28j60。
uip_ipaddr(ipaddr, 211,86,58,250); // 目的地址
uip_connect((uip_ipaddr_t *)ipaddr , HTONS(8080) );
也定义了#define UIP_ACTIVE_OPEN 1
#define UIP_ACTIVE_OPEN 1
跪求大神给点意见.
自己顶... 移植的uip1.0服务器模式性能还可以,客户端就是连不上,没有执行uip_connect函数,不明白为什么 你在局域网内试过吗
这个服务器是公网IP还是局域网内电脑,如果能ping同说明链接是没有问题的,建议你用交叉线或者通过交换机直接连接电脑试试,排除是不是路由器设置的问题 看你的IP应该是公网IP,你去检查一下你现在路由器是否设置了一些不该设置的东西 不是这个问题,我改了ip192.168系列的也是一样,就是不能主动连上
void tcp_appcall(void)
{
/*if(uip_conn->rport == HTONS(RemotePort))
{
tcp_client_appcall();
}*/
switch(uip_conn->rport) {
case HTONS(RemotePort):
if(uip_timedout()||uip_aborted()||uip_closed()){
#if AUTO_RECONNECT
/*reconnect to server*/
//delay_sec(5);
uip_ipaddr_t ipaddr;//定义IP类型变量
uip_ipaddr(ipaddr, RemoteIP, RemoteIP, RemoteIP, RemoteIP); //远程IP
uip_connect(&ipaddr, HTONS(RemotePort));//建立到远程端口
#endif
}else if(uip_connected()){
#if 1
/*is connected ok*/
uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
"Hello,I connected to you! thanks."));
#endif
}else if(uip_rexmit()){
#if 1
/*need retransmission last packet*/
uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
"this is retransmission packet"));
#endif
}else if(uip_poll()){
/*poll connecte is idle*/
#if 1
// uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
// "Hi, we are idle"));
uip_send("idle",4);
#endif
}else if(uip_acked()){
/*get a ack for send packet ok*/
#if 0
uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
"this is a second packet."));
#endif
if(uip_newdata()){
goto newdata_with_acked;
}
}else if(uip_newdata()){
newdata_with_acked:
#if 1
/*receving a new data*/
memcpy(AppData, uip_appdata, uip_len);
data_len=uip_len;
uip_send(AppData,data_len);
#endif
}else{
/*error*/
}
break;
default:
/*discard packet*/
break;
}
} lou0908 发表于 2013-5-28 16:19 static/image/common/back.gif
看你的IP应该是公网IP,你去检查一下你现在路由器是否设置了一些不该设置的东西 ...
改了ip试了一下,依旧是客户端模式能ping通不能主动连上,服务器模式没问题,好像uip_connect这个函数就没有执行 我用的uip0.9 的客户端模式,感觉什么都没改,1.0不一样么?
/* Initialize the ARP 初始化ARP*/
uip_arp_init();
/* Initialize the uIP TCP/IP stack. 初始化uIP的TCP/ IP协议栈*/
uip_init();
/*set host MAC addr设置主机的MAC地址*/
uip_ethaddr.addr = 0x12;
uip_ethaddr.addr = 0x34;
uip_ethaddr.addr = 0x56;
uip_ethaddr.addr = 0x78;
uip_ethaddr.addr = 0x90;
uip_ethaddr.addr = 0xAB;
#if UIP_FIXEDADDR == 0
/*host ip addr主机IP地址*/
uip_ipaddr(ipaddr, 192,169,13,201);
uip_sethostaddr(ipaddr);
/*netmask addr网络掩码地址*/
uip_ipaddr(ipaddr, 255,255,255,0);
uip_setnetmask(ipaddr);
/*router ip addr路由器的IP地址*/
uip_ipaddr(ipaddr, 192,169,13,1);
uip_setdraddr(ipaddr);
#endif
/*connect to server连接服务器*/
uip_ipaddr(ipaddr, 192,169,13,14);
uip_connect(ipaddr, HTONS(SERVER_PORT));
// SFRPAGE = SMB0_PAGE; //设置从机地址
SMB0ADR = (0x01<<1)&0xFE; //不使能全局呼叫地址(0x00)识别
while(1)
{
TaskA();
}
}
void TaskA(void)
{
uint8 xdata i, arptimer,Ledtimer;
//while (1)
{
// SFRPAGE = CONFIG_PAGE;
Delayms(50);
Ledtimer++;
if(Ledtimer%10==0)
LedState = ~LedState;
// if(I2CErrCnt>100)
// LedState3=~LedState3;
// if(I2CErrCnt>0)
// LedState2=~LedState2;
// for(TestCnt=0;TestCnt<TESTNUM;TestCnt++)
// {
// RiOrder = TestData;
// }
// RevOrderCnt = TESTNUM;
// OSTaskResume(ID_COMMANDPARSING);
// SFRPAGE = SMB0_PAGE;
// STA = 1;
uip_len = dev_poll();
if(uip_len == 0)
{
for(i = 0; i < UIP_CONNS; i++)
{
uip_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0.
如果以上函数调用的数据应该被发送到网络
全局变量uip_len设置为>0的值。*/
if(uip_len > 0)
{
uip_arp_out();
dev_send();
}
}
/* Call the ARP timer function every 10 seconds.
每10秒调用一次ARP定时器功能*/
if(++arptimer == 20)
{
uip_arp_timer();
arptimer = 0;
}
Delayms(1);
}
else
{
if(BUF->type == htons(UIP_ETHTYPE_IP))
{
uip_arp_ipin();
uip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0.
如果以上函数调用的数据应该被发送到网络
全局变量uip_len设置为>0的值。 */
if(uip_len > 0)
{
uip_arp_out();
dev_send();
}
}
else if(BUF->type == htons(UIP_ETHTYPE_ARP))
{
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0.
如果以上函数调用的数据应该被发送到网络
全局变量uip_len设置为>0的值。*/
if(uip_len > 0)
{
dev_send();
}
}
}
}
}
/*uIP call back func回调函数*/
void uip_appcall(void)
{
switch(uip_conn->rport) {
case HTONS(SERVER_PORT):
if(uip_timedout()||uip_aborted()||uip_closed()){
#if AUTO_RECONNECT
/*reconnect to server重新连接到服务器*/
Delayms(1000);
//NetIni();
uip_connect(ipaddr, HTONS(SERVER_PORT));
#endif
}else if(uip_connected()){
#if 1
/*is connected ok 是否连接OK*/
uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
"Hello,I connected to you! thanks."));
#endif
}else if(uip_rexmit()){
#if 1
/*need retransmission last packet需要重传最后一个包*/
// uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
// "this is retransmission packet"));
uip_send("this is retransmission packet",30);
#endif
}else if(uip_poll()){
/*poll connecte is idle 轮询连接处于闲置状态*/
#if 1
// uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
// "Hi, we are idle"));
//uip_send("idle",4);
#endif
}else if(uip_acked()){
/*get a ack for send packet ok得到一个ACK发送包OK*/
#if 0
uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
"this is a second packet."));
#endif
if(uip_newdata()){
goto newdata_with_acked;
}
}else if(uip_newdata()){
newdata_with_acked:
#if 1
/*receving a new data接收一个新的数据*/
// uip_appdata = ((char*)&uip_len);
// uip_appdata = ((char*)&uip_len);
// uip_send(uip_appdata,uip_len+2);
uip_send("OK thanks",10);
#endif
}else{
/*error*/
}
break;
default:
/*discard packet丢弃数据包*/
break;
}
} 您好·我也遇到同样问题,好纠结·希望能问问你看··谢谢了 爱看下雪 发表于 2014-4-21 15:45
您好·我也遇到同样问题,好纠结·希望能问问你看··谢谢了
我之前用的同样 的代码是好的,放了一段时间,现在回来再用,怎么都连接不上服务器了,也是Uip做客服端的,你问题解决了吗,共同交流下啊
页:
[1]