I'm working on a university project to create a J2ME emulator, using J2SE API. Therefore, in order to allow HTTP connections to J2ME applications, I'm using a from the J2SE API. However I'm stucked with it, because I have to check if the instance is in the connected state, but there is no method available to return it. Does anyone knows if there is a way to know that?
So you ask; and either you get, or you timeout. Right?
I use HttpURLConnection. I set one up at start up and use it over again all day long. Only gives a problem if the remote server that I'm trying to connect to goes down, or was never up.
Why do you need to check on connected()?
"No one appreciates the very special genius of your conversation as the dog does."
Joined: Feb 16, 2004
Well, the problem is that I'm trying to create a J2ME emulator, and for that, I'm using J2SE API to provide J2ME services in the way the J2ME API specifies. For that, I'm making a wrapper for HTTP, in a way that I use a J2SE HttpURLConnection to simulate the behavior of a J2ME HttpConnection. The problem is that they have different behavior regarding methods that cause the transition to the connected state, and also they behave differently on when to return exceptions. For example, in J2ME, if I open a HTTP connection, and call connection.getDate(), this causes the connection to go to the connected state; therefore, if I call the method connection.setRequestProperty(), this method should throw an IOException, because the connection will be at the connected state. If I do the same on a instance of J2SE HttpURLConnection, no exception is thrown. Therefore I have to check if the connection is in the connected state in order to return the IOException. Can anyone help me on this issue? Any hints?
Joined: Jan 29, 2003
Ah, a much more interesting problem for sure! Just for grins, see if you can "cheat" and use reflection to change the visibility of the protected "connected" boolean. See if it even has the right value at the right time.