• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

C and Java Programming

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want send Data from C client to Java Server Socket,Infact Java client is working well with Java Serversocket, However problem with C client, pls help me to get off from this problem
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

There are really no special problems. If you're sending binary data, you should send it from C in "network byte order" using functions in the hton(), ntoh(), but you should always do that anyway. Then on the Java end, you'd use a DataInputStream/DataOutputStream combination.

What problems are you having?
 
amit bamby
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok C client is sending database URL and Classpath to Java Server , n Java Server uses JDBC to connect to database using url and classpath string provided by C client, infact in java server i m using StringTokenizer to break the string into url and classpath

Now pls tell me how to approach on this issue
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're just exchanging text, then even the network-byte-order rule is irrelevant. So as I said, what problems are you having? What errors are you seeing?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me chime in here, since I am trying to figure out how to do the same thing. On the server (Java) side, here's my simple code:



On the C side, I am simply doing :



However, when I run the C client after having started the Java server, this is what I see:


What should I be doing differently here? Anyone else try to do this before? I tried removed the "+ 1" from the third argument of send() since Java strings are not null-delimited, but I still got the EOFException. The C program exits normally (I'm checking the return code from send()), so I know the client is sending the data. Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,

Well, if you're going to use readUTF(), then the C program has to write UTF data. The definition for the format is here; look for the part about the readUTF() method. It's unfortunately much more complex than just sending the characters!

An alternative, if you're just sending text, is to use your existing C code and do this in Java:

BufferedReader reader = new BufferedReader(s.getInputStream())
String st = reader.readLine();
 
Peter Aarestad
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:
Hi Peter,

Well, if you're going to use readUTF(), then the C program has to write UTF data. The definition for the format is here; look for the part about the readUTF() method. It's unfortunately much more complex than just sending the characters!



I found that just before I came back to this forum. Basically, it's not so bad for plain old ASCII - I coded up a general-purpose function in C that emulates Java's protocol, and it looks like it works pretty well. Thanks for your help!
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic