Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to transport 2 dimension array of integer using byte array.  RSS feed

 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Does anyone here know how to transport 2 dimension array of integer using byte array?

Thank you so much beforehand.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have the byte array requirement? Wouldn't it be a lot simpler to serialize the array?
 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have the byte array requirement?


Because I need to send the byte array to C++ application. And as far as I know, C++ don't have serialized method.

Thank you.
 
Paul Clapham
Sheriff
Posts: 22472
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then your C++ application must have some explicit instructions about how to encode a 2-dimensional array of integers into an array of bytes. Or alternatively it may not be capable of handling that array. At any rate the question cannot be answered without examining the C++ program, or its specifications.
 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At below I have paste the C++ code (Server and Client). However I will not use the client-side code. Java applet will runs in the client-side.

Right now I still don't know how to send 2 dimensional array of integer to C++ application.
Could somebody tell me how to do this?

Thank you so much.

This is Server-side code:


This is Client-side code:
 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I can send a byte array from Java to C++ application using ByteArrayOutputStream class.
But when C++ returns the byte array back to Java, the following exception occurs:

java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at EchoJava.main(EchoJava.java:83)


Does anyone can tell me the mechanism of this exception or how this exception is called? Better yet, anyone can tell me how to avoid this kind of exception?

By the way this is how I send the byte array (from C++):


Please help and Thank you very much.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!