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
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
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...
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)?
>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>