File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Java client and C server socket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Java client and C server socket" Watch "Java client and C server socket" New topic
Author

Java client and C server socket

Akil Kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 83
Hi all,

Can anyone please help me on this query?
I have a server written in C and client in Java. I need to establish a tcp/ip connection between them.
Right now I am able to set a socket connection from my Java client program and created an input stream which is continuously reading data from the server.
I need to read based on the server's protocol. The server has a message header and few other information as a C program. Basically all information are being sent as packets.
I know the number of bytes for each data structure.
Now how can I read that from my java client in the same order? Do I need to wrap the io stream object to accept bytes?
All the data in the server is like raw data. Can anyone guide me how to receive data from server?

Thanks
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
If you have an InputStream, then you can use that to read single or multiple bytes, can't you?
Akil Kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 83
Yes I will be able to read multiple bytes. But how can I format my data while reading? Currently when I run my program it connects to the server and keep reading continuously.

while(true){

System.out.println(in.read());

}

But I need to have the data in the console in an ordered / formatted manner. Do I need to loop through the data and split it based on how the data is laid out in server protocol?

Thanks
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You can read the bytes into a stack and extract the information from that. Or just write directly into the datastructure that you expected.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java client and C server socket