Sharing Binary Data with non Java Apps

G

Gerry

Hi.

I'm have an existing game written in C/C++ which can be played over the
Internet.
The protocol simply transmits the messages in binary Big Endian format.
Assembling and disassembling the messages are pretty straight forward
in C.

I am trying to create a Java version of the game which is compatible
with my existing protocol. I am very new to networking in Java and how
to transmit non-text data in Java.
Is there a simple way to do something simple as convert 4 bytes into a
32-bit signed integer and vice versa?

I've noticed that the BigInteger class does something close, but it
would require a convoluted path to get what I need.

I've read about Object Serialization, but that seems more suited for
sharing data between Java programs.


It seems very simple to do high-level networking stuff in Java, but when
it comes to doing low level stuff it isn't very straight forward how to
do it.


Any help or pointers to web pages would be appreciated.
Thanks.
 
C

Chris Smith

Gerry said:
I'm have an existing game written in C/C++ which can be played over the
Internet.
The protocol simply transmits the messages in binary Big Endian format.
Assembling and disassembling the messages are pretty straight forward
in C.

I am trying to create a Java version of the game which is compatible
with my existing protocol. I am very new to networking in Java and how
to transmit non-text data in Java.
Is there a simple way to do something simple as convert 4 bytes into a
32-bit signed integer and vice versa?

See java.io.DataInputStream and java.io.DataOutputStream. They are
ideal for what you're trying to do. If you prefer a more low-level I/O
interface, java.nio.IntBuffer would work in your case, too.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
G

Gerry

Chris Smith said:
See java.io.DataInputStream and java.io.DataOutputStream. They are
ideal for what you're trying to do. If you prefer a more low-level I/O
interface, java.nio.IntBuffer would work in your case, too.

Thanks.

My main problem is how I would assemble the bytes after they're read
though.
And how to break down a value into bytes when sending data.

And how to deal with Endianess.
Won't the output be different on machines which are Little Endian?


java.nio.IntBuffer isn't available since I'm trying to run on Java 1.1
if at all possible. Which is probably not advisable. But I'm running on
MacOS 9 where Java 1.1.8 is the latest version available for the
platform.
I'll be getting a newer machine soon, but until then, I'm limited to
Java 1.1.
 
C

Chris Smith

Gerry said:
My main problem is how I would assemble the bytes after they're read
though.

Yes, that's what DataInputStream does for you.
And how to break down a value into bytes when sending data.

And that's what DataOutputStream does for you.
And how to deal with Endianess.
Won't the output be different on machines which are Little Endian?

Nope, those two classes always work with big-endian data. The API
documentation for the classes says as much. I suggest that you read it
before getting too much further.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
G

Gerry

Chris Smith said:
Yes, that's what DataInputStream does for you.


And that's what DataOutputStream does for you.


Nope, those two classes always work with big-endian data. The API
documentation for the classes says as much. I suggest that you read it
before getting too much further.

My apologies.
The first time I looked, all I saw were methods for reading/writing
bytes. Perhaps I was looking at the wrong class.

I see now that DataInput/OutputStream also allow reading/writing various
primitive data types.

Thank you for the pointers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,037
Latest member
MozzGuardBugs

Latest Threads

Top