Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java Micro Edition
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Secure Financial Transactions with Ansible, Terraform, and OpenSCAP
this week in the
Cloud/Virtualization
forum!
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
Jeanne Boyarsky
Bear Bibeault
Sheriffs:
Rob Spoor
Henry Wong
Liutauras Vilda
Saloon Keepers:
Tim Moores
Carey Brown
Stephan van Hulst
Tim Holloway
Piet Souris
Bartenders:
Frits Walraven
Himai Minh
Jj Roberts
Forum:
Java Micro Edition
Connecting MIDlets to Servlets
Yavor lvanov
Greenhorn
Posts: 14
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi, this is very simple question turned into a headache for me.
I've got the following code on the server side:
import javax.servlet.http.*; import javax.servlet.*; import java.io.*; public class HitServlet extends HttpServlet { private int mCount; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String message = "Hits: " + ++mCount; response.setContentType("text/vnd.wap.wml"); response.setContentLength(message.length()); PrintWriter out = response.getWriter(); out.println(message); } }
And this is what my MIDlet looks like, a simple one again:
import java.io.*; import javax.microedition.io.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class HitMIDlet extends MIDlet implements CommandListener { private Display mDisplay; private Form mMainForm; private StringItem mMessageItem; private Command mExitCommand, mConnectCommand; public HitMIDlet() { mMainForm = new Form("HitMIDlet"); mMessageItem = new StringItem(null, ""); mExitCommand = new Command("Exit", Command.EXIT, 0); mConnectCommand = new Command("Connect", Command.SCREEN, 0); mMainForm.append(mMessageItem); mMainForm.addCommand(mExitCommand); mMainForm.addCommand(mConnectCommand); mMainForm.setCommandListener(this); } public void startApp() { mDisplay = Display.getDisplay(this); mDisplay.setCurrent(mMainForm); } public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void commandAction(Command c, Displayable s) { if (c == mExitCommand) notifyDestroyed(); else if (c == mConnectCommand) { Form waitForm = new Form("Waiting..."); mDisplay.setCurrent(waitForm); Thread t = new Thread() { public void run() { connect(); } }; t.start(); } } private void connect() { HttpConnection hc = null; InputStream in = null; String url = "http://www.mobilekid.co.uk:8080/midp/hits"; try { hc = (HttpConnection)Connector.open(url); in = hc.openInputStream(); int contentLength = (int)hc.getLength(); byte[] raw = new byte[contentLength]; int length = in.read(raw); in.close(); hc.close(); // Show the response to the user. String s = new String(raw, 0, length); mMessageItem.setText(s); } catch (IOException ioe) { mMessageItem.setText(ioe.toString()); } mDisplay.setCurrent(mMainForm); } }
When I
test
it on the WTK 2.5 emulator it works fine, however, when deployed on my E61 I got a java.io.IOException -5105.
Your help and advices are much appreciated! Thank you!
Rashid Mayes
Ranch Hand
Posts: 160
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this may help. looks like the error is
tcpip6_error_NoRoute -5105 IPv6: No route available
from
http://newlc.com/article.php3?id_article=117
maybe the access point is not set up correctly.
Rashid Mayes
http://www.hostj2me.com/ -
http://www.worlddeveloper.org/
marimuthu kumaravel
Greenhorn
Posts: 1
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
private Command mExitCommand;
anyone explain this detail
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
J2ME and RMI or CORBA
Problem with servlet running on linux.
User-Agent is not being send + midlet
java lang ClassNotFoundException
Null URL Exception
More...