×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Aug 2008
    Location
    Sri Lanka, Colombo
    Posts
    204

    Thumbs down Communicate with a localhost

    hi guys,

    i'm trying to communicate with a localhost through emulator.
    but it throws an exception "Connection not found"

    cn anyonoe help me out????


    String url = "http://localhost:8080/Til";
    System.out.println(url);
    HttpConnection hcon = (HttpConnection) Connector.open(url);
    DataInputStream ios = hcon.openDataInputStream();
    sb = new StringBuffer();
    int ch;
    while ((ch = ios.read()) != -1) {
    sb = sb.append((char) ch);
    }
    frm.append(sb.toString());


    regards,
    Randika

  2. #2
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Communicate with a localhost

    Where web server is running, on computer or on emulator?

  3. #3
    Regular Contributor
    Join Date
    Aug 2008
    Location
    Sri Lanka, Colombo
    Posts
    204

    Re: Communicate with a localhost

    it runs on my local computer

  4. #4
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Communicate with a localhost

    Nokia Emulator shares localhost with local computer.
    On which emulator are you trying to this?
    Try opening a web browser in the emulator and opening url "http://localhost:8080/Til" in it. Tell what happens.

  5. #5
    Regular Contributor
    Join Date
    Aug 2008
    Location
    Sri Lanka, Colombo
    Posts
    204

    Re: Communicate with a localhost

    i'm using nokia 6131 NFC emulator as well as sprint emulator.
    as far as i concern it's nt possible to open a browser in emulator.

    do i have to use a stream connection or a socket connection in order to communicate with a localhost?????

    regards,
    randika

  6. #6
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Communicate with a localhost

    Quote Originally Posted by HasithaRandika View Post
    i'm using nokia 6131 NFC emulator as well as sprint emulator.
    as far as i concern it's nt possible to open a browser in emulator.
    Why not?
    Just go to All Programs >> S60 Developer Tools >> SDK >> Version >> Emulator
    and press Applications key on the emulator and then select web browser.

    Quote Originally Posted by HasithaRandika View Post
    do i have to use a stream connection or a socket connection in order to communicate with a localhost?????
    I tested on Sun WTK Emulator and HttpConnection with URL as http://192.168.1.2/ works fine in it. (192.168.1.2 is the IP address of my PC)

  7. #7
    Regular Contributor
    Join Date
    Aug 2008
    Location
    Sri Lanka, Colombo
    Posts
    204

    Thumbs down Re: Communicate with a localhost

    hi guys so sorry to say still i couldn't figur it out. it throws

    second exception.. TCP open
    third exception. TCP open
    nullpointer exception

    what's wrong here can anyone help me out????

    here's the code

    public class CustomerClient extends MIDlet implements CommandListener {

    private Display disply;
    private Form frm;
    private Command request;
    private String tot;
    String parameter = "?method=requestPin&msg=";
    private TextField name, nic, card;
    private StringBuffer sb;

    public void startApp() {
    disply = Display.getDisplay(this);
    frm = new Form("");
    name = new TextField("Full Name", "", 20, TextField.ANY);
    nic = new TextField("NIC", "", 10, TextField.ANY);
    card = new TextField("Card Id", "", 30, TextField.ANY);
    request = new Command("Request", Command.OK, 1);
    frm.append(name);
    frm.append(nic);
    frm.append(card);
    frm.addCommand(request);
    frm.setCommandListener(this);
    disply.setCurrent(frm);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command arg0, Displayable arg1) {
    if (arg0 == request) {
    tot = name.getString() + "@" + nic.getString() + "@" + card.getString();
    Connect c = new Connect();
    c.start();
    }
    }

    public class Connect extends Thread {

    public void run() {
    String url = "http://124.43.48.9:8084/sgms/";
    HttpConnection hcon = null;
    try {
    System.out.println("about to connect....");
    hcon = (HttpConnection) Connector.open(url);
    System.out.println("connect....");
    } catch (IOException ex) {
    System.out.println("frist exception.." + ex.getMessage());
    frm.append(ex.getMessage());
    }
    try {
    System.out.println(hcon.getResponseCode());
    } catch (IOException ex) {
    System.out.println("Second exception.." + ex.getMessage());
    frm.append(ex.getMessage());
    }
    try {
    if (hcon.getResponseCode() == HttpConnection.HTTP_OK) {
    DataInputStream ios = hcon.openDataInputStream();
    sb = new StringBuffer();
    int ch;
    while ((ch = ios.read()) != -1) {
    sb.append((char) ch);
    }
    }
    } catch (IOException ex) {
    System.out.println("third exception.." + ex.getMessage());
    frm.append(ex.getMessage());
    }
    frm.append(sb.toString());
    }
    }
    }

  8. #8
    Regular Contributor
    Join Date
    Aug 2008
    Location
    Sri Lanka, Colombo
    Posts
    204

    Thumbs up Re: Communicate with a localhost

    hi guys good news is i sort it out instead of the IP jst put localhost.
    it works fine.. thanks guys

    kind regards,
    Randika

Similar Threads

  1. XMLSocket to localhost problem
    By MatBru in forum [Archived] Flash Lite on Nokia Devices
    Replies: 24
    Last Post: 2009-12-16, 10:42
  2. 6230 DKU-2 cable and linux
    By krisek in forum General Development Questions
    Replies: 1
    Last Post: 2005-02-04, 09:03
  3. Replies: 0
    Last Post: 2003-09-16, 05:20
  4. D211 new linux driver 1.04 not working !!
    By franz_meyer in forum Multimodecards
    Replies: 1
    Last Post: 2002-12-12, 08:31

Posting Permissions

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