• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

send audio and text via one http connection?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to send an audio file (converted to a byte array) and text data in one http output stream from a J2ME cell phone client that is MIDP 1.0.

What is the easiest way to do this and still be able to differentiate the audio byte array from the text data on the servlet side?

I have done alot of googling on this and don't seem to find a straightforward solution:

-MIME content type "multipart/mixed" seems plausible, but I only see it used in email clients, and I'm not sending an email message

- I see Michael Yuan says you can send an image file as a byte array over http using DataOutputStream, but how would you send text data, too? Should you set up your own token system? Perhaps you could insert the byte array length into the DataOutputStream, read it on the servlet side starting at the offset for length number of bytes? And then assume everything after that is string data?

...or is there another way? I assume this is the same as sending an image as a byte array...

Thanks!
 
author
Posts: 1436
6
Python TypeScript Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I do:



On the other end, you can reconstruct the data.

 
Pam Ludford
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a million, I'll give that a try!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

I want to do something similar (Send a file in bytes).
I am doing like that:

J2ME

String requestString = "POST message";

hc = ( HttpConnection )Connector.open( url, Connector.READ_WRITE );
hc.setRequestMethod( HttpConnection.POST );

dos = hc.openDataOutputStream();

byte[] requestBody = requestString.getBytes();
dos.writeInt (requestBody.length);
dos.write(requestBody, 0, requestBody.length);
dos.writeUTF ("utf string");

Servlet's doPost

is = request.getInputStream();
dis = new DataInputStream(is);

byte [] audiodata = null;
int length = dis.readInt();
dis.readFully(audiodata, 0, length);
String text = dis.readUTF ();

Then I send a response message back to the midlet

I receive a null pointer exception in

dis.readFully(audiodata, 0, length);

One time only (dont know why) I received an end of file exception in the same line!

the int and udf write/reading works ok (they are there for testing)

any ideas please?
 
thanos ton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doh!
ok sorry,
the byte array was obviously null...
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic