File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes send audio and text via one http connection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "send audio and text via one http connection?" Watch "send audio and text via one http connection?" New topic
Author

send audio and text via one http connection?

Pam Ludford
Greenhorn

Joined: Jan 04, 2005
Posts: 4
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!
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
This is what I do:



On the other end, you can reconstruct the data.



Seam Framework: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
Pam Ludford
Greenhorn

Joined: Jan 04, 2005
Posts: 4
Thanks a million, I'll give that a try!
thanos ton
Greenhorn

Joined: Jan 14, 2005
Posts: 2
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

Joined: Jan 14, 2005
Posts: 2
doh!
ok sorry,
the byte array was obviously null...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: send audio and text via one http connection?