Re: socket communication: socket doesn't connect



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 the
Visual Tools & Languages > C/C++ & Visual C++ > vc.language forum at


http://msdn.microsoft.com/newsgroups/default.aspx?&guid=&sloc=en-us&dg=microsoft.public.vc.language&p=1&tid=e730aa77-f91f-41f4-9c1f-12a17efbcc97

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



.



Relevant Pages

  • Re: JVM/Java memory footprint
    ... I found that if I use Java for developing the CLI ... application I will be exhausting the memory of our Application Server ... to make the JVM shareable. ... multiple client processes? ...
    (comp.lang.java.programmer)
  • Re: What multi-tier components to use
    ... Enterprise Java Beans. ... > with every change in the parameter list, you could make your new server ... But surely if you have an old client and the interfaces are still valid on ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Best Programming language for Network programming (serious server application
    ... back to the client. ... So the server needs to be a heavily multi- ... required to display the same on a real-time basis. ... I m wondering of using java for my client application development ...
    (comp.programming)
  • Re: Pushing data from the server to the client
    ... have data pushed from the Java webservice to your client? ... > information on the client machine, and it's never any older than ... So I mocked up a facade web service on my side in .NET ... > the remoting dll on each client machine and the stub on the server. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Pushing data from the server to the client
    ... have data pushed from the Java webservice to your client? ... > information on the client machine, and it's never any older than ... So I mocked up a facade web service on my side in .NET ... > the remoting dll on each client machine and the stub on the server. ...
    (microsoft.public.dotnet.framework.webservices)

Loading