×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    12

    J2ME SOCKET HELP

    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); }

    }
    }
    Last edited by elvis10ten; 2012-09-23 at 20:43.

  2. #2
    Registered User
    Join Date
    Aug 2012
    Posts
    12

    Re: J2ME SOCKET 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); }

    }
    }

Similar Threads

  1. Asynchronous socket in j2me
    By kumar1234567 in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2013-10-01, 22:25
  2. sending message from j2se socket to j2me socket
    By gizyy in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2010-05-10, 07:14
  3. Native Symbian Socket Server & J2ME Socket Client
    By romantr in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2010-04-21, 07:37
  4. Does J2ME support the Web Socket API
    By KevinBoyd in forum Mobile Java General
    Replies: 1
    Last Post: 2009-09-20, 10:24
  5. does s40 support j2me socket
    By wdynasty in forum Mobile Java General
    Replies: 4
    Last Post: 2008-11-19, 13:51

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×