• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transfer Vector over HTTP

 
Yavor lvanov
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to transfer a vector over an HTTP response message. I am not sure how exactly I can achieve that. Here is a sample code I wrote where I got stuck:




If we assume the 'someURL' returns a Vector, you can notice the 'data' byte array holds it. Any ideas how to construct it out of the byte array?

Thanks!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you seen this?
http://www.coderanch.com/t/230700/JME/Mobile/Vecrot-Object-web-Sservice
 
Yavor lvanov
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I'm working on a RESTful application, however, I don't like the solution of streaming back a string containing several other strings, and then trying to read that on the client. For my application it's more practical to return a Vector containing a dynamic number of elements of different types. I know there is a soultion, however, I am struggling a bit with its implementation.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
REST has the advantage of small overhead and ease of implementation, but if you're looking at a heterogeneous collection of binary objects, it's more likely you'd either want Java serialized data or something like SOAP.

Java serialized data tends to be incompatible between different Java implementations, so it's usually not good to use with mobile devices.

SOAP can encapsulate all sorts of things, but of course it's fairly high overhead.
 
Rashid Mayes
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yavor, I think you would be pleasently suprised about how efficient and easy REST is from a mobile developers standpoint. That said, you could expand the use of the DataInput/DataOutput streams.

Lets use a vector of strings as an example. On the server side you could 1) write the number (vector size) of strings using dos.writeInt, 2) loop through the vector writing each string with dos.writeUTF. On the client site you would 1) read the number of strings with dis.readInt, 2) loop for "the number of strings" interations reading a string each iteration with dis.readUTF.

You can use similar logic to write structured data or other complex objects, but you may find REST more extensible and benefit from its platform independence.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic