TO handle a Server Initiated http Request
HI,
I am developing a J2me application which is communicating with a http Servlet, The application is working fine when an request is sent from the client and the response received successfully too.
But what if theserveritself has toinitiatesome request and send it to client, is there any way to catch that request data?
Thanks and Regards
Raaghu.K
# 1
well... in this case your servlet will be a "client" and your J2ME application should be a "server". Since there is not any default implementation of HTTP Server in MIDP you will not be able to get such funtionality by default. But you can try to implement some simple server by yourself, using ServerSocket class. In this case you will need to parse all HTTP Headers & request Body by yourself.
# 2
If you must use Http, your probably better off just 'polling' the server for data. You'll have a really had time getting the phone to accept http connections, and it'll be hard to make it work on more than one device.
Just have the phone connect to the server every once in a while to check for new data. If there is data being sent to the phones on a regular basis, make it poll every couple seconds, if it's not very often you can have it wait longer: 10s, 20s, minutes...
If you really need fast 2-way communication with the phone, http is unfortunately going to be a painful limiting factor. Can you use Sockets at all? If so, maybe have the http servlet spawn a thread to open a server-socket or use nio socket channels if you are going to have many devices. Pretty much every Midp2.0 phone can open a socket connection.