This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java Micro Edition and the fly likes J2ME and RMI or CORBA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "J2ME and RMI or CORBA" Watch "J2ME and RMI or CORBA" New topic
Author

J2ME and RMI or CORBA

omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
Hi, i have just stated with the J2ME and i want to know
if my MIDlet application can use CORBA or RMI
and how can i show an image in my Form.
regards, omar
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well J2ME does contain SocketConnections and you could use such to contact RMI. However, usually, because of the costs association with Wireless, most outside calls are done stateless and quick request response, which tends to lead to Servlets on the server-side handling all your work for you. So the Servlet could use RMI on behalf of the wireless device, if needed.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
Hi, and thanks Mark for replying.
i found a servlet and a small MIDlet
that can read from this servlet some info
but i was wondering how i can send some data
to the servlet from my MIDlet.
here are the two classes:
/*the Servlet: */
public class ss extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void destroy() {
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String message = "Greeting from the Server:\nOmar" ;
response.setContentType("text/plain");
response.setContentLength(message.length());
PrintWriter out = response.getWriter();
out.println(message);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}

}

/* the MIDlet */

import java.io.*;

import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class HitServlet
extends MIDlet
implements CommandListener {
private Display mDisplay;
private Form mMainForm;
private StringItem mMessageItem;
private Command mExitCommand, mConnectCommand;

public HitServlet() {
mMainForm = new Form("HitServlet");
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 = getAppProperty("HitServlet.URL");
//System.out.println("this is the url: " + url);


try {
hc = (HttpConnection)Connector.open("http://localhost:8081/servlet/ss");
in = hc.openInputStream();

int contentLength = (int)hc.getLength();
System.out.println(contentLength+"") ;

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("Error: " + ioe.toString());
}
mDisplay.setCurrent(mMainForm);
}
}

Regards, Omar
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: J2ME and RMI or CORBA
 
Similar Threads
what is RMI
Books on RMI/CORBA
Software for RMI and CORBA
RMI and j2me
RMI-IIOP apps X CORBA apps - question.