Please i want to view www.smsme.cu.cc in j2me using socket. I have tried many ports with it but i don't get any content what should i do ?. I am the owner of smsme.cu.cc too. Please any code or suggestion will help. Here is the code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
public class Example extends MIDlet implements CommandListener {
private Form google;
private String url = "socket://";
private TextField search;
private Form form;
private Display display = Display.getDisplay(this);
private Command ok;
public void startApp() {
form = new Form("ELVIS");
ok = new Command("search", Command.OK, 1);
search = new TextField("search", "Google", 900, TextField.ANY);
form.append(search);
form.addCommand(ok);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
void connection(String url) throws IOException{ SocketConnection sc = null; InputStream is = null; StringBuffer buffer = new StringBuffer(); try{ sc = (SocketConnection) Connector.open(url + search.getString()); is = sc.openInputStream(); int chars; while((chars = is.read()) != -1){ buffer.append((char) chars); } System.out.println (buffer.toString()); google = new Form("searching"); google.append(buffer.toString()); }finally{ if(is != null){ is.close(); } if(sc != null){ sc.close(); } } }
public void commandAction(Command c, Displayable d) {
if(c == ok) { try { connection(url); } catch(IOException e) { } display.setCurrent(google); }
}
}

Reply With Quote

