socket IO on MIDP

I opened a TCP stream connection between my MIDlet and a server. The connection is established, and what the MIDlet writes to the server is received fine, but when the server writes back an answer (a short test string), it is not picked up by the MIDlet. It waits on read forever, and if available is called on it, 0 is returned. There is no broken connection because netstat shows that this connection is still established. What could be the problem?

[465 byte] By [myungsun] at [2007-9-26 4:13:44]
# 1
Did you close the connection from ur midlet? coz it mite happen if you havent closed ur stream and the server still expects something from ur Midlet and its hanging. netstat also says the same thing.HTHRaj
rajagopalv at 2007-6-29 13:20:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

Your general idea is correct; however, if you close the stream, the peer complains the connection was aborted and won't do anything afterwards although it does finish reading. In JDK, calling instead Socket.shutdownOutput forces an EOF at the end of the stream and seems to take care of situations like this. The question is, in MIDP, you don't have anything equivalent... what to do?

myungsun at 2007-6-29 13:20:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
I have never done Socket prog. on MIDP but used HttpConnection and it always works only when I close the stream(Which looks logical). Do u get a Connection reset if u close the stream. Doesnt it happen when u close the socket connection?
rajagopalv at 2007-6-29 13:20:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

yes, you do get a connection reset if you close the stream, which may be not be what you want if you want information going back and forth. In any case, I found a solution by resorting to an old-fashioned method of sending a termination character and having the receiver watch for it to terminate the read. As for Http vs. socket, if I'm writing a proprietary application authoring both the server and the MIDP client sides, isn't socket stream preferable as you can trim your data excahnge to the bare essentials without all the HTTP protocol-related extras? Also on this subject, do you know if there is some method that's considered the best way to go about having your MIDlet access a website? Is it to have a special proxy or gateway server to intermediate between the MIDlet and the website, parsing away and tailoring the web content for MID-size screens? Like chopping away at an oak tree to carve out a toothpick?

myungsun at 2007-6-29 13:20:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
Here, I would like to ask the same thing that how can we directly connect to URL or W3 page? I tried using proxy setting and port no but unable to do it.Please advise any other way out?RegardsDeepdeep@cwc.nus.edu.sg
d_n_singh at 2007-6-29 13:20:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

Proxy Question?

Depends which version of the midp you are using. The latest midp1.0.3 supports tunneling (of course using the http interface). There are a lot of issues with proxies and tunneling solves them. You should be able to set the conf file for proxy and it will work. Once the http connection gets to the proxy the tunneling feature will establish a connection to your end web server. Try telnet-*** to the proxy to make sure you can get to it.

socketIO Question?

As far as the original question about socketIO. Remember NOT USING the http interface on the client requires that you basically replace all that code in the server app and the midp app. So all the message headers, control chars, and so on.....

Are you using the Http servlet interface on the web server?

kmfinn at 2007-6-29 13:20:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
If you are using an InputStream, 0 is always returned from available() because it needs to be overriden by something like DataInputStream.
spotell at 2007-6-29 13:20:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8
hi.can anyone plz show how to send a PNG image file through a raw socket (from a j2se server to a midlet) ?thanks
lust4MIDP at 2007-6-29 13:20:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...