• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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.
 
(instanceof Sidekick)
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.
 
Marshal
Posts: 24488
55
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.
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!