• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2-dimension array data streaming.

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

I am always having hard time when dealing with java array.
This time I want to stream a 2-dimension array into a file and send it through TCP/IP socket.

How do I do that?

Thank you so much beforehand.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, what have you tried? Have you been able to send other data? There are a lot of protocol options. It would be great if you've already chosen one and made it work for something simple. If not, we can talk about the listener on the other end and some of the choices.
 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stan,

Thank you for the quick reply, honestly I didn't expect to be this fast (the thing I like about this forum )

what have you tried? Have you been able to send other data?


Actually I have been able to send a DatagramPacket through DatagramSocket, but now I want to make a TCP/IP connection; no luck so far .
But before I get into that, I think I need to put the data to be send; which is in form of 2-dimensional int array, into a file. As fas as I see I need to change the 2-dimensional int array into byte[] so it can be buffered, but don't know how.

I am sorry if I make a stupid statements, I am still learning....

Thank you so much.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Turning your data into byte[] is one choice. Another is to use Java Serialization which is ideal for sending objects over the wire. HERE is an example using arrays.

Sounds like you ought to back up though and think about arrays separate from your socket goal. What you're calling a 2-dimensional array is really an array where every entry is another array, or more simply an array of arrays. Can you write code to iterate through all the elements in such an array?
 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again Stan,

Just want to say thanks for your direction.
Java Serialization is what I need indeed.

Good luck and God Bless You...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic