这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 紧急求助!关于vxworks下socket问题。。。

共8条 1/1 1 跳转至

紧急求助!关于vxworks下socket问题。。。

菜鸟
2006-12-21 03:46:25     打赏




不知道什么原因,可能vxworks的某个组件没加、BSP不完善、板卡问题?我现在碰到个问题,困恼了我好久依旧没解决——vxworks服务器端一直阻塞在accept处,windows客户端在connect后返回为-1,两者连不上。

(我在vxworksARM2440板卡上)中加载了socket服务器程序,在win下运行自己编的客户端程序,另外,我在win下也编了个服务器程序,win下的客户端可以和win下的服务器正常通信。)

串口打印信息为:

0x33f805ac (tDbgTask): This is just server_socket test ...


after socket return 4

after bind return 0

after listen return 0

在shell下 ifShow后显示为:

-> ifShow
dmf (unit number 0):
Flags: (0x8863) UP BROADCAST RUNNING ARP MULTICAST
Type: ETHERNET_CSMACD
Internet address: 192.168.0.99
Broadcast address: 192.168.0.255
Netmask 0xffffff00 Subnetmask 0xffffff00
Ethernet address is 1a:2b:3c:4d:5e:6f
Metric is 0
Maximum Transfer Unit size is 1500
58 packets received; 6 packets sent
46 multicast packets received
1 multicast packets sent
0 input errors; 0 output errors
0 collisions; 0 dropped
lo (unit number 0):
Flags: (0x8069) UP LOOPBACK RUNNING ARP MULTICAST
Type: SOFTWARE_LOOPBACK
Internet address: 127.0.0.1
Netmask 0xff000000 Subnetmask 0xff000000
Metric is 0
Maximum Transfer Unit size is 32768
0 packets received; 0 packets sent
0 multicast packets received
0 multicast packets sent
0 input errors; 0 output errors
0 collisions; 0 dropped
value = 0 = 0x0

在PC上抓包为:

[IMG]http://images.blogcn.com/2006/12/20/10/sunbin1010,20061220191756.jpg[/IMG]

[IMG]http://images.blogcn.com/2006/12/20/12/sunbin1010,2006122023547.jpg[/IMG]

[IMG]http://images.blogcn.com/2006/12/20/10/sunbin1010,2006122019417.jpg[/IMG]

下面分别是vxworksserver)、windowsclient)下的源码:

vxworks:

#include "vxWorks.h"
#include "sockLib.h"
#include "taskLib.h"
#include "inetLib.h"
#include "stdioLib.h"
#include "ioLib.h"
#include "sioLib.h"
#include "string.h"
#include "stdLib.h"
#include "stdio.h"

#define MYPORT 2001
#define BACKLOG 3


int serverfunc(void)
{
char buf[1024];
char * clientip;
struct sockaddr_in client;
struct sockaddr_in server;

int sk;
int newsk;
int namelen;
int pktlen;
int temp1,temp2,temp3;

logMsg("%s\n\n","This is just server_socket test ...",0,0,0,0,0);


if ((sk=socket(AF_INET, SOCK_STREAM, 0))<0)
{
logMsg("%s","Socket build fail",0,0,0,0,0);
return (-1);
}

printf("\nafter socket return %d\n",sk);


memset((char *)&server,'\0',sizeof(server));
server.sin_family = AF_INET;

server.sin_len = sizeof(server);
server.sin_port = htons(MYPORT);
server.sin_addr.s_addr = INADDR_ANY;

if ((temp2=bind(sk, (struct sockaddr *)&server, sizeof(server)))==-1)
{
logMsg("%s","Bind() fail",0,0,0,0,0);
return (-1);
}

printf("\nafter bind return %d\n",temp2);

if ((temp3=listen(sk,BACKLOG))==-1)
{
logMsg("%s","Listen() fail",0,0,0,0,0);
return (-1);
}

printf("\nafter listen return %d\n",temp3);

namelen = sizeof(client);
if ((newsk = accept(sk, (struct sockaddr *)&client, &namelen)) ==-1)
{
logMsg("%s","Accept() fail",0,0,0,0,0);
printf("Accept() fail");
return (-1);
}

clientip=inet_ntoa(client.sin_addr);
logMsg("Got connect from: %s\n",clientip,0,0,0,0,0);

printf("\nnew fs is:%d\n",newsk);

while(1)
{
if ((pktlen = recv(newsk,buf,1024,0))<0)
{
logMsg("%s","Recv()",0,0,0,0,0);
break;
}
else
if (pktlen == 0)
{
logMsg("\n%s\n\n","Connection is shut down!\n\n",0,0,0,0,0);
break;
}
else
{
buf[pktlen]='\0';
logMsg("\n\"%s\" said: %s",clientip,buf,0,0,0,0);
}


}

close(newsk);
close(sk);

return 0;
}

windows:

#include <stdio.h>
#include <winsock.h>
#include "string.h"

#pragma comment(lib,"Ws2_32")

#define MAXSIZE 2048
#define sendport 2001

int argc=2;

struct sockaddr_in ClientAddr;

SOCKET sock;

DWORD startSock()
{
WSADATA WSAData;

if(WSAStartup(MAKEWORD(2,2),&WSAData)!=0)
{
printf("sock init fail");
return(-1);
}

sock = socket(AF_INET, SOCK_STREAM, 0);

return 1;
}


int client(int argc, char *argv[])
{
u_int numbyte;
char buf[MAXSIZE];

if (argc != 2)
{
fprintf(stderr,"usage: client hostname\n");
exit(1);
}

if(startSock()==1)
{
printf("\nStart Socket successfully!\n");
}
else
{
printf("Error!");
return 0;
}

ClientAddr.sin_family = AF_INET;
ClientAddr.sin_port = htons(sendport);
ClientAddr.sin_addr.s_addr = inet_addr(argv[1]);

if(connect(sock, (struct sockaddr *)&ClientAddr,sizeof(struct sockaddr))==0)
{
printf("\nConnect successfully!\n");
printf("\nThe port number to send: %d",sendport);
printf("\nThe IP to send: %s\n",argv[1]);
}
else
{
printf("\nConnect unsuccessfully!\n");
return 0;
}

getchar();

while(1)
{

printf("\nPlease input the data you want send: ");

gets(buf);

if(strcmp(buf, "quit") == 0 )
{
closesocket(sock);
return 0;
}

int iLen = strlen(buf);

buf[iLen] = 0xa;
buf[iLen+1] = '\0';
numbyte=send(sock, buf, strlen(buf), 0);
if(numbyte==SOCKET_ERROR)
{
printf("\nSend error!\n");
closesocket(sock);
break;
}

}
return 0;
}


void main()
{
char *argv[2],hostname[10],hostip[15];
argv[0]=hostname;
argv[1]=hostip;
printf("This is just client_socket test ! Input \"quit\" to exit...\n\n");
// printf("Input host name: ");
// scanf("%s",argv[0]);
printf("\nInput host IP: ");
scanf("%s",argv[1]);
puts("\n");
client(argc,argv);
}

[align=right][color=#000066][此贴子已经被作者于2006-12-20 23:10:05编辑过][/color][/align]



关键词: 紧急     求助     关于     vxworks     socket         

菜鸟
2006-12-22 05:53:00     打赏
2楼

书上的东西不全是对的

[align=right][color=#000066][此贴子已经被作者于2006-12-21 22:07:53编辑过][/color][/align]

菜鸟
2006-12-22 19:14:00     打赏
3楼

有没有什么解释的~


菜鸟
2006-12-22 22:42:00     打赏
4楼

根据抓包看来,win下的客户端发出TCP握手协议SYN后,目标板并没有回应SYN/ACK包。

是不是vxworks的某个网络组件没加上啊。

几天了,还没连上,郁闷之极啊。。。


菜鸟
2006-12-27 18:36:00     打赏
5楼

考虑参加上海双实vxworks培训


菜鸟
2006-12-27 20:08:00     打赏
6楼

我在PPC8260的板子上测试你的代码,没有问题。你检查一下你的字节序吧,主要在端口号的地方,看一下报文里面来的跟你本地的是否一致。下面是server端的打印。

-> serverfunc
0x1746e38 (tShell): This is just server_socket test ...


after socket return 6

after bind return 0

after listen return 0

0x1746e38 (tShell): Got connect from: 10.159.12.26

new fs is:7

0x1746e38 (tShell):
"10.159.12.26" said: d:\program.prg
0x1746e38 (tShell):
"10.159.12.26" said: adafdf


菜鸟
2006-12-31 07:02:00     打赏
7楼
北京有培训VXWORKS的吗?

菜鸟
2007-01-01 06:58:00     打赏
8楼

kankan


共8条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]