Re: socket communication: socket doesn't connect
- From: Ananya <Ananya@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 27 Apr 2007 00:22:00 -0700
Thanks for your response!
Ok, now in my connectServer method I am no more calling the connect method,
but I am calling the accept method from WinSock2.h. Well, the accept method
also returns -1.
Before calling the accept method, WSAGetLastError() returns 0, and
afterwards it returns 10035.
Please help!
"Michael K. O'Neill" wrote:
"Ananya" <Ananya@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message.
news:6E597362-E344-4299-84DE-91835941DC4A@xxxxxxxxxxxxxxxx
I originally published my question with the title above in thehttp://msdn.microsoft.com/newsgroups/default.aspx?&guid=&sloc=en-us&dg=microsoft.public.vc.language&p=1&tid=e730aa77-f91f-41f4-9c1f-12a17efbcc97
Visual Tools & Languages > C/C++ & Visual C++ > vc.language forum at
and I was told that it really belongs here. So here it is again:
I am trying to establish socket communication between my C++ and Java
program.
I bring up the Java program from the C++ program with ShellExecEx.
Then I start in the Java program with:
int port = 3000;
int rev = 1;
InetAddress address = InetAddress.getLocalHost();
Client client = new Client(port, address, rev);
int[] ints = new int[1];
ints[0] = 1;
client.send_ints(ints, 1);
client.closesocket();
using my Java Client class.
Then I continue in my C++ program with:
int port = 3000;
Server* server = new Server(port);
server->connectServer();
using my C++ Server class.
It looks like the server gets constructed properly and the connectServer
method calls the connect method from WinSock.h, which I have included (and
its library WSock32.Lib is at Additional Dependences in the Input of the
Linker).
Why does this connect method from WinSock.h return - 1?
< snip >
To determine why connect() is failing, call WSAGetLastError() and tell us
its value. It might be something like WSAENOTSOCK or WSAENOTINITIALISED
You explanation reverses the "typical" roles of client and server. In a
typical scenario, it's the client that calls connect() to connect to the
server, whereas in your example, it's the server that's calling connect() to
connect to the client. Was that intentional? Frankly, since your C++
Server class is apparently calling bind() and listen(), the Java client
should be the one calling Connect(), and your C++ server should be accepting
these connections by calling accept().
Mike
- Follow-Ups:
- Re: socket communication: socket doesn't connect
- From: Dave Lowther
- Re: socket communication: socket doesn't connect
- References:
- socket communication: socket doesn't connect
- From: Ananya
- Re: socket communication: socket doesn't connect
- From: Michael K. O'Neill
- socket communication: socket doesn't connect
- Prev by Date: Re: TCP/IP application problem running on Vista
- Next by Date: Re: socket communication: socket doesn't connect
- Previous by thread: Re: socket communication: socket doesn't connect
- Next by thread: Re: socket communication: socket doesn't connect
- Index(es):
Relevant Pages
|
Loading