Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can't connect to Windows using sockets??

35 views
Skip to first unread message

agin

unread,
Jan 2, 2002, 2:12:01 PM1/2/02
to
I am unsuccessfully trying to connect from a vxWorks client to
a win2k server using sockets.

I can connect from win2k to vxWorks, vxWorks to vxWorks, win2k to win2k but
I am unable to connect from vxWorks to win2k.

I am using winsock2.

Is there something I am missing?


Here is snipet of the vxWorks client code:

clientSock = socket (AF_INET, SOCK_STREAM, 0);

serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(SERVER_NUM);
if (connect (clientSock, (struct sockaddr *)&serverAddr, sizeof
(serverAddr)) == ERROR)
{
printf ("Connect failed:\n");
printErrno(errnoGet());

close (clientSock);
return (ERROR);
}


Here is a snipet of the Windows Server code:
u_long nInterfaceAddr = inet_addr(pcAddress);
if (nInterfaceAddr != INADDR_NONE) {
SOCKET sd = socket(AF_INET, SOCK_STREAM, 0);
if (sd != INVALID_SOCKET) {
sockaddr_in sinInterface;
sinInterface.sin_family = AF_INET;
sinInterface.sin_addr.s_addr = nInterfaceAddr;
sinInterface.sin_port = nPort;
if (bind(sd, (sockaddr*)&sinInterface,
sizeof(sockaddr_in)) != SOCKET_ERROR) {
listen(sd, 1);
return sd;
}
}
}

accept(sd, (sockaddr*)&sinRemote, sizeof(sinRemote));


art


Donald McLachlan

unread,
Jan 2, 2002, 2:37:13 PM1/2/02
to
Can you ping from vxworks to the win2k server?
Can you use something like tcpdump or windump or ethereal to see what is happening
to the packets on the wire?
What errors/error messages are you getting?

Does "SERVER_NUM" == "nPort", and maybe that should be "htons(nPort)".

Don

--
Donald McLachlan E-mail Donald.M...@crc.ca
Communications Research Centre / RNS Tel (613) 998-2845
3701 Carling Ave., Fax (613) 998-9648
Ottawa, Ontario
K2H 8S2
Canada


agin

unread,
Jan 2, 2002, 6:51:13 PM1/2/02
to
Hey Donald:

Thanks for your reply.

I can ping the Win2k server from the vxworks.

The client gives me a refused connection error.

I am using 4242 as my port number for simplicity.

art
"Donald McLachlan" <d...@mars.dgrc.crc.ca> wrote in message
news:a0vnh9$ec7$1...@crc-news.crc.ca...

P B

unread,
Jan 3, 2002, 2:57:30 AM1/3/02
to
> > > Here is snipet of the vxWorks client code:
> > >
> > > clientSock = socket (AF_INET, SOCK_STREAM, 0);
> > >
> > > serverAddr.sin_family = AF_INET;

Are you also passing the correct IP address of the server that you
are connecting to?

> > > serverAddr.sin_port = htons(SERVER_NUM);
> > > if (connect (clientSock, (struct sockaddr *)&serverAddr, sizeof
> > > (serverAddr)) == ERROR)
> > > {
> > > printf ("Connect failed:\n");
> > > printErrno(errnoGet());
> > >
> > > close (clientSock);
> > > return (ERROR);
> > > }
> > >
> > >
> > > Here is a snipet of the Windows Server code:
> > > u_long nInterfaceAddr = inet_addr(pcAddress);
> > > if (nInterfaceAddr != INADDR_NONE) {
> > > SOCKET sd = socket(AF_INET, SOCK_STREAM, 0);
> > > if (sd != INVALID_SOCKET) {
> > > sockaddr_in sinInterface;
> > > sinInterface.sin_family = AF_INET;
> > > sinInterface.sin_addr.s_addr = nInterfaceAddr;
> > > sinInterface.sin_port = nPort;
> > > if (bind(sd, (sockaddr*)&sinInterface,
> > > sizeof(sockaddr_in)) != SOCKET_ERROR) {
> > > listen(sd, 1);

perhaps you can try changing it to listen(sd, 5)

> > > return sd;
> > > }
> > > }
> > > }
> > >

do you see the server on the w2K system listening? u can check using
netstat. did you try connecting using telnet (telnet IP_ADDR PORT_NUM)?

Dave Korn

unread,
Jan 8, 2002, 12:16:39 PM1/8/02
to
agin wrote in message
<5YIY7.21096$xM1.86...@newssvr14.news.prodigy.com>...

>I am unsuccessfully trying to connect from a vxWorks client to
>a win2k server using sockets.

>Here is snipet of the vxWorks client code:


>
> clientSock = socket (AF_INET, SOCK_STREAM, 0);
>
> serverAddr.sin_family = AF_INET;
> serverAddr.sin_port = htons(SERVER_NUM);
> if (connect (clientSock, (struct sockaddr *)&serverAddr, sizeof
>(serverAddr)) == ERROR)

>Is there something I am missing?

You forgot to set the sin_addr member in the serverAddr struct. When
you're about to bind a listening socket, you don't need to specify
sin_addr - the socket will bind to and listen on all interfaces - but when
you're connecting an outgoing socket, you *have* to tell it the IP address
of the server you want to connect to! Could this be because you cut+pasted
the code to set up serverAddr from the server software to the client
software?

DaveK
--
moderator of
alt.talk.rec.soc.biz.news.comp.humanities.meow.misc.moderated.meow
Burn your ID card! http://www.optional-identity.org.uk/
Help support the campaign, copy this into your .sig!
Proud Member of the Exclusive "I have been plonked by Davee because he
thinks I'm interesting" List
Member #<insert number here>

0 new messages