• Post Reply Bookmark Topic Watch Topic
  • New Topic

java and c socket problem

 
Kike Pedraza
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all, i have this program in java which works with sockets, made a test java client and no prob, i have this c program with sockets, no prob with a test c client, but when i mix the java prog with the c prog it goes kind of crazy, first is not working, then it works when i run both in debug mode and breakpoint int certain steps, then its working properly, then it stops working...

i'm working with eclipse ide (in case it helps)

i am running the c program in another machine; both java programs are in the same machine.

Any experience with sockets communication with a external c program? Any suggestion?
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exceptions are being thrown in the Java code?

What ERRNO values are being returned in C? And what calls are they returned from?

What happens if you run both client and server from outside the IDE?

Guy
 
Kevin Mangold
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've had this problem before. My mistake was my use of CR (\r) and LF (\n). I know that C/C++ can be a bit particular with these.
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kike!

Are you converting from "Host" byte order to "Network" byte order?
If you are using a *nix OS to run the C code, check out the Network-To-Host and Host-To-Network functions, ie... noths, ntohl, htons, htonl. The C program needs to call the hton* function before sending to the Java code.
I'm not sure how this applies to the Windows environment, maybe someone else can chime in?

Darrin
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!