Sockets in J2ME

Hi friends
I want to use Sockets in my J2ME application. How can use sockets?
I am trying to connect to remote server. So is there need to write server side program. I have written a server side program which uses JAVA sockets, And it listens for socket connection.
I want to know what I am doing is right?
And how can achieve socket connection in my J2ME application.?
its Urgent
Thanks in advance.

Thanks
I have used sockets same as in Network Demo program given in WTK.
I have written my J2ME application & used ScocketConnection.
I have written one Java server program with ServerSocket in it..
Now when I run my J2ME application on WTK emulator it is working fine & it also establishes connection with server program.
But when I actually install this program on mobile it is unable to connect.
What could be the problem?
I am using Nokia 6681.
It is giving following error
java.io.IOException : SymbianOS error = -5105 route not found
or sometimes it gives error as
java.io.IOException : general error 9 during TCP write

Similar Messages

  • Im Stuck, error in my server (j2se socket) with j2me (socket)

    I dunt understand, previous worked, now (2.3beta wireless toolkit) doenst work anymore, u guys can help me?
    SERVER CODE J2SE
    package com.pc.jwolf.server.testes;
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    public class Teste01 {
         public Teste01() throws IOException {
              ServerSocket s = new ServerSocket(3131);
              Socket sx = s.accept();
              DataInputStream input = new DataInputStream(sx.getInputStream());
              DataOutputStream output = new DataOutputStream(sx.getOutputStream());
              output.flush();
              int c = 0;
              StringBuffer b = new StringBuffer();
              while((c=input.read()) != -1) b.append((char) c);
              System.out.println(new String(b));
         public static void main(String[] args) {
              try {
                   new Teste01();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    }MOBILE CODE (J2ME) CLDC 1.1 Profile 2.0
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.SocketConnection;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    public class Midlet extends MIDlet {
         protected void startApp() throws MIDletStateChangeException {
              // TODO Auto-generated method stub
              try {
                   SocketConnection sc = (SocketConnection) Connector
                             .open("socket://127.0.0.1:3131");
                   DataInputStream input = sc.openDataInputStream();
                   DataOutputStream out = sc.openDataOutputStream();
                   out.flush();
                   out.writeUTF("HELLO WORLD!!!!!!");
                   out.flush();
              } catch (Exception e) {
                   // TODO: handle exception
                   e.printStackTrace();
         protected void pauseApp() {
              // TODO Auto-generated method stub
         protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
              // TODO Auto-generated method stub
    }My server cant read the message... whats wrong?
    Tkz.

    Hi,
    I the exact same problem. I didn't quite understand what you meant by closing the socket. When i close the socket on the server side before I enter the whole look it throws an exception. Could please help out and maybe paste a little code to explain further.
    Thank you

  • Problem if mail sent using sockets using j2me devices

    Hi,
    I have a strange problem. I am sending a mail using j2me ( using sockets ). The mail will be sent successfully. But when tried to access using pop service, that mail is never seen in the server.
    I sent a mail from j2me device to gmail account - I can see that mail using the gmail login, but using pop service i am not able to see that mail.
    If I send a mail from browser - I can see the mail in both, the browser and also the pop service.
    Can anyone explain what is the problem ?
    Thanks in advance

    Would you be so kind as to edit your original post and add [SOLVED] to the subject?
    Thanks,
    Craig...

  • SSL Server Socket and j2me

    I make a SSL Server Socket. I want that a cell connect to it for take data. I have to make Certificate form my server. this is for a Stage so I can't pay for certificate. If I make my self signed cert can I install it to a cell or this operation is blocked?

    Sorry, I make an SSL Server Socket using java and this server stays on a pc.

  • Bluetooth and j2me, a frustrating scenario...

    Hello all,
    I don't want to use propeitory sdk's so I need to get a bluetooth stack working with the wireless toolkit but I am not going to pay for it so I downloaded the stack from javabluetooth.org, but when trying to compile a program which uses the javax.bluetooth package I get an error...
    Error preverifying class org.javabluetooth.distributed.BluetoothTCPServer
        VERIFIER ERROR org/javabluetooth/distributed/BluetoothTCPServer.run()V:
    Cannot find class java/net/SocketI guess j2me api does not include the package socket at all?
    Does anyone have any ideas how to get a bluetooth stack working with j2me?
    Thanks for your time
    poncenby

    the WTK 2.2b is available since June 26 or so.
    To the JSR-82 API: the classes from sun (javax.bluetooth.* and javax.obex.*) are part of the WTK 2.2b and can be used. But remember: to use a bt app on a phone, the phone must support JSR82, not only MIDP and CLDC.
    I am too good for this world. You should check http://java.sun.com/j2me . There can at least 2 articles be found regarding the development of J2ME and Bluetooth, as well as the WTK downloads and many other interesting things ;-)
    here is the link to the WTK 2.2b
    http://java.sun.com/products/j2mewtoolkit/download-2_2.html
    good luck and have fun
    Killer_2001

  • J2ME question"INTUITIVE_TOOLKIT"

    Hi everyone, i quoted this from informIT.com website.can anyone tell me what do they mean by the "INTUITIVE_TOOLKIT". that would help a lot. thanks
    "Even though we said that Sun's J2ME Wireless Toolkit only supports the http communication, there is actually an undocumented feature that will let you run socket or datagram programs under the Toolkit if you set the environment variable ENABLE_CLDC_PROTOCOLS=INTUITIVE_TOOLKIT".
    And: Has anyone programmed sockets using J2ME, please give me some info that will help me regarding the issue above.
    Thanks

    Enabling this feature will let you use Sockets
    so you can do
    con = (StreamConnection)Connector.
         open( "socket://" + host + ":" + port,
                    Connector.READ_WRITE );That said, I think sockets are enabled by default now.

  • TCP connections and running in the background

    First of all I am new to j2me, but with very good java background
    I want to create a db server running in the background of a symbian phone.
    Does anyone knows if it is possible to open tcp sockets in j2me?
    Is it possible at all to run a java app in the background on a phone?
    I am using ngage if that is relevant.

    The following examples show how a SocketConnection would be used to access a sample loopback program. (from api documentation of WTK 2.2)
       SocketConnection sc = (SocketConnection)
                             Connector.open("socket://host.com:79");
       sc.setSocketOption(SocketConnection.LINGER, 5);
       InputStream is  = sc.openInputStream();
       OutputStream os = sc.openOutputStream();
       os.write("\r\n".getBytes());
       int ch = 0;
       while(ch != -1) {
           ch = is.read();
       is.close();
       os.close();
       sc.close();
    Since MIDP 2.0

  • Socket Programing in J2ME - Confused with Sun Sample Code

    Hai Everybody,
    I have confused with sample code provided by Sun Inc , for the demo of socket programming in J2ME. I found the code in the API specification of J2ME. The code look like :-
    // Create the server listening socket for port 1234
    ServerSocketConnection scn =(ServerSocketConnection) Connector.open("socket://:1234");
    where Connector.open() method return an interface Connection which is the base interface of ServerSocketConnection. I have confused with this line , is it is possible to cast base class object to the derived class object?
    Plese help me in this regards
    Thanks in advance
    Sulfikkar

    There is nothing to be confused about. The Connector factory creates an implementation of one of the extentions of the Connection interface and returns it.
    For a serversocket "socket://<port>" it will return an implementation of the ServerSocketConnection interface. You don't need to know what the implementation looks like. You'll only need to cast the Connection to a ServerSocketConnection .

  • J2ME in Pocket PC - sockets - serial port

    Hi Guys,
    I am writing a J2ME application for a Pocket PC using Windows Mobile 2003
    I have chosen the J9 VM to run my J2ME applications on the PPC.
    My application will use tcp/ip sockets communication to connect to a server. Do you know if there are any issues of using this part of J2ME on a Pocket PC?? ( I have tested the same application on Java enabled mobile phone and it is fine)
    I also want to access the serial port from my J2ME application (read/write data). Do you know if it is possible to do it on a Pocket PC through the normal way?? (using the javax.microedition.io package??)

    evelknievel you said that implemmented bluetooth
    connection like a serial link, where can i find some
    documentation to do that?i am sorry, that i cannot offer you a link to a tutorial, because i just tried it out by myself using an iPAQ h5550 with windows CE 4.2 (i think this is equivlent to PocketPC 2003, or 2003 SE) which is able to create such connections. the bluetooth-driver of each side of your "serial bluetooth link" has to implement the so called "serial port profile". maybe you should google for it...
    i found some information on this:
    "To open the connection using the:
    * PocketPC
    o Most Bluetooth drivers for PocketPC provide the mapping between Bluetooth serial ports and virtual COM (inbound/outbound) ports. For example WIDCOMM Bluetooth driver (BTW-CE 1.4) that comes with hp iPAQ h5550 by default assigns COM port 5 as the inbound Bluetooth serial port and COM port 8 as the outbound Bluetooth serial port. These COM ports are configurable from the driver's Bluetooth manager."
    i found it here:
    http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/15987c8cb752ead786256dc20070b433?OpenDocument
    hopefully this information is useful to you or anybody else :)
    best regards
    evelknievel

  • Socket error in j2me

    Hi,
    Here is the scenario:
    I have a servlet application hosted on the Tomcat webserver [ver 3.2.1] on the internet. The client midlet applicaiton is run on the j2me emulators from sun and codewarrior. The entire application works great ..
    Now, a different team uses Acompli 008 over GPRS network (test env) and runs the same midlet client application. Almost evertime I see this error message on my webserver --
    2001-06-21 03:42:53 - ContextManager: SocketException reading request, ignored - java.net.SocketException: Connection
    reset by peer: JVM_recv in socket input stream read
    at java.net.SocketInputStream.socketRead(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:86)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:186)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:204)
    at org.apache.tomcat.service.http.HttpRequestAdapter.doRead(HttpRequestAdapter.java:115)
    at org.apache.tomcat.core.BufferedServletInputStream.doRead(BufferedServletInputStream.java:106)
    at org.apache.tomcat.core.BufferedServletInputStream.read(BufferedServletInputStream.java:128)
    at javax.servlet.ServletInputStream.readLine(ServletInputStream.java:138)
    at org.apache.tomcat.service.http.HttpRequestAdapter.readNextRequest(HttpRequestAdapter.java:129)
    at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:195)
    at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
    at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
    at java.lang.Thread.run(Thread.java:484)
    I'm using httpconnection syntax, POST method for data transmission and the data size is approx 1-2K bytes.
    After this error message pops on my webserver screen, the client device freezes ..
    Do anyone have any ideas or suggestions or solutions ??? Is anyone aware of this or encountered this error message ??
    The worst part is that i'm unable to even simulate this using the emulators ..
    Thanks a lot in advance ..
    S.

    Perhaps you could post your code on the forum so that we might be able to help you better?
    Anyway, check also if you are using a get or post request from the midlet cus the Post requests have been known to give a few people problems.

  • Sockets and FileConnection in J2ME

    hi
    can anyone pls help me with FileConnection in j2me...i want my j2me program to read from a file.....do i need to download additinal package, if yes, which one?
    I also need some guidance in j2me socket programming....i want my j2me client program to establish a socket connection with a normal java server program on the same PC....any references pls...
    thank u

    Look at the URLs below:
    How to Access Local File Systems from J2ME devices using FileConnection API
    http://www.java-tips.org/content/view/109/73/
    Opening and reading a file on the mobile device
    http://www.java-tips.org/content/view/352/73/
    How to use mobile as a network server
    http://www.java-tips.org/content/view/526/73/

  • Is my code right?(J2ME socket communication)

    If i run this code in my emulator i get i get an IOException at at com.sun.cldc.io.j2me.socket.Protocol.openPrim(+7)
    Can u please tell me where i've gone wrong.
    Thanks
    Here goes the code...
    try
    com.sun.cldc.io.j2me.socket.Protocol p = null;
    String url = "socket://10.0.1.244:2500";
    p = (com.sun.cldc.io.j2me.socket.Protocol)Connector.open(url,Connector.WRITE,true);
    DataOutputStream dos = p.openDataOutputStream();
    dos.writeUTF("this is my message");
    dos.flush();
    dos.close();
    }catch(IOException e)
    e.printStackTrace();
    }

    hi.
    can anyone plz show how to send a PNG image file through a raw socket (from a j2se server to a midlet) ???
    your code looks ok, nhikaripur.
    thanks

  • J2ME socket programming

    i am doing a final year project in which i have a java program running on pc connected to internet which uses bsnl as an isp.i am provided with a public ip
    i have a J2me client.I connect the mobile to internet with gprs.
    I use gprs wap settings of vodafone which uses proxies.i have searched internet
    and found out that i dont access actual internet using gprs wap. ie we only access wap sites.i want to try purely socket communications.i am using n72 mobile for midlets and socket communications.
    sc = (SocketConnection)Connector.open("socket://my bsnl ip:5000");
    is = sc.openInputStream();
    os = sc.openOutputStream();
    i have used simulator and tried communication it was successful.
    i tried socket communications form internet client and my server
    i also tried different ports too.
    now with actual n72 mobile i am having a problem of socket communication.
    summary of problems
    1.Is direct socket communication possible through gprs with client on N72
    with a java server
    2.Do i have to use wap settings or internet settings of vodafone

    here is my client on mobile..it is same as networkdemo in suns WTK2.5
    we used it for testing the connection...
    SocketMIdlet:
    package socket;
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class SocketMIDlet extends MIDlet implements CommandListener {
    private static final String SERVER = "Server";
    private static final String CLIENT = "Client";
    private static final String[] names = { SERVER, CLIENT };
    private static Display display;
    private Form f;
    private ChoiceGroup cg;
    private boolean isPaused;
    private Server server;
    private Client client;
    private Command exitCommand = new Command("Exit", Command.EXIT, 1);
    private Command startCommand = new Command("Start", Command.ITEM, 1);
    public SocketMIDlet() {
    display = Display.getDisplay(this);
    f = new Form("Socket Demo");
    cg = new ChoiceGroup("Please select peer", Choice.EXCLUSIVE, names, null);
    f.append(cg);
    f.addCommand(exitCommand);
    f.addCommand(startCommand);
    f.setCommandListener(this);
    display.setCurrent(f);
    public boolean isPaused() {
    return isPaused;
    public void startApp() {
    isPaused = false;
    public void pauseApp() {
    isPaused = true;
    public void destroyApp(boolean unconditional) {
    if (server != null) {
    server.stop();
    if (client != null) {
    client.stop();
    public void commandAction(Command c, Displayable s) {
    if (c == exitCommand) {
    destroyApp(true);
    notifyDestroyed();
    } else if (c == startCommand) {
    String name = cg.getString(cg.getSelectedIndex());
    if (name.equals(SERVER)) {
    server = new Server(this);
    server.start();
    } else {
    client = new Client(this);
    client.start();
    Client:
    package socket;
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class Client implements Runnable, CommandListener {
    private SocketMIDlet parent;
    private Display display;
    private Form f;
    private StringItem si;
    private TextField tf;
    private boolean stop;
    private Command sendCommand = new Command("Send", Command.ITEM, 1);
    private Command exitCommand = new Command("Exit", Command.EXIT, 1);
    InputStream is;
    OutputStream os;
    SocketConnection sc;
    Sender sender;
    public Client(SocketMIDlet m) {
    parent = m;
    display = Display.getDisplay(parent);
    f = new Form("Socket Client");
    si = new StringItem("Status:", " ");
    tf = new TextField("Send:", "", 30, TextField.ANY);
    f.append(si);
    f.append(tf);
    f.addCommand(exitCommand);
    f.addCommand(sendCommand);
    f.setCommandListener(this);
    display.setCurrent(f);
    * Start the client thread
    public void start() {
    Thread t = new Thread(this);
    t.start();
    public void run() {
    try {
    sc = (SocketConnection)Connector.open("socket://59.95.23.211:4000");
    si.setText("Connected to server");
    is = sc.openInputStream();
    os = sc.openOutputStream();
    // Start the thread for sending messages - see Sender's main
    // comment for explanation
    sender = new Sender(os);
    // Loop forever, receiving data
    while (true) {
    StringBuffer sb = new StringBuffer();
    int c = 0;
    while (((c = is.read()) != '\n') && (c != -1)) {
    sb.append((char)c);
    if (c == -1) {
    break;
    // Display message to user
    si.setText("Message received - " + sb.toString());
    stop();
    si.setText("Connection closed");
    f.removeCommand(sendCommand);
    } catch (ConnectionNotFoundException cnfe) {
    Alert a = new Alert("Client", "Please run Server MIDlet first", null, AlertType.ERROR);
    a.setTimeout(Alert.FOREVER);
    a.setCommandListener(this);
    display.setCurrent(a);
    } catch (IOException ioe) {
    if (!stop) {
    ioe.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    public void commandAction(Command c, Displayable s) {
    if ((c == sendCommand) && !parent.isPaused()) {
    sender.send(tf.getString());
    if ((c == Alert.DISMISS_COMMAND) || (c == exitCommand)) {
    parent.notifyDestroyed();
    parent.destroyApp(true);
    * Close all open streams
    public void stop() {
    try {
    stop = true;
    if (sender != null) {
    sender.stop();
    if (is != null) {
    is.close();
    if (os != null) {
    os.close();
    if (sc != null) {
    sc.close();
    } catch (IOException ioe) {
    Sender:
    package socket;
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class Sender extends Thread {
    private OutputStream os;
    private String message;
    public Sender(OutputStream os) {
    this.os = os;
    start();
    public synchronized void send(String msg) {
    message = msg;
    notify();
    public synchronized void run() {
    while (true) {
    // If no client to deal, wait until one connects
    if (message == null) {
    try {
    wait();
    } catch (InterruptedException e) {
    if (message == null) {
    break;
    try {
    os.write(message.getBytes());
    os.write("\r\n".getBytes());
    } catch (IOException ioe) {
    ioe.printStackTrace();
    // Completed client handling, return handler to pool and
    // mark for wait
    message = null;
    public synchronized void stop() {
    message = null;
    notify();
    Server:
    package socket;
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class Server implements Runnable, CommandListener {
    private SocketMIDlet parent;
    private Display display;
    private Form f;
    private StringItem si;
    private TextField tf;
    private boolean stop;
    private Command sendCommand = new Command("Send", Command.ITEM, 1);
    private Command exitCommand = new Command("Exit", Command.EXIT, 1);
    InputStream is;
    OutputStream os;
    SocketConnection sc;
    ServerSocketConnection scn;
    Sender sender;
    public Server(SocketMIDlet m) {
    parent = m;
    display = Display.getDisplay(parent);
    f = new Form("Socket Server");
    si = new StringItem("Status:", " ");
    tf = new TextField("Send:", "", 30, TextField.ANY);
    f.append(si);
    f.append(tf);
    f.addCommand(exitCommand);
    f.setCommandListener(this);
    display.setCurrent(f);
    public void start() {
    Thread t = new Thread(this);
    t.start();
    public void run() {
    try {
    si.setText("Waiting for connection");
    scn = (ServerSocketConnection)Connector.open("socket://:4000");
    // Wait for a connection.
    sc = (SocketConnection)scn.acceptAndOpen();
    si.setText("Connection accepted");
    is = sc.openInputStream();
    os = sc.openOutputStream();
    sender = new Sender(os);
    // Allow sending of messages only after Sender is created
    f.addCommand(sendCommand);
    while (true) {
    StringBuffer sb = new StringBuffer();
    int c = 0;
    while (((c = is.read()) != '\n') && (c != -1)) {
    sb.append((char)c);
    if (c == -1) {
    break;
    si.setText("Message received - " + sb.toString());
    stop();
    si.setText("Connection is closed");
    f.removeCommand(sendCommand);
    } catch (IOException ioe) {
    if (ioe.getMessage().equals("ServerSocket Open")) {
    Alert a = new Alert("Server", "Port 5000 is already taken.", null, AlertType.ERROR);
    a.setTimeout(Alert.FOREVER);
    a.setCommandListener(this);
    display.setCurrent(a);
    } else {
    if (!stop) {
    ioe.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    public void commandAction(Command c, Displayable s) {
    if ((c == sendCommand) && !parent.isPaused()) {
    sender.send(tf.getString());
    if ((c == Alert.DISMISS_COMMAND) || (c == exitCommand)) {
    parent.notifyDestroyed();
    parent.destroyApp(true);
    * Close all open streams
    public void stop() {
    try {
    stop = true;
    if (is != null) {
    is.close();
    if (os != null) {
    os.close();
    if (sc != null) {
    sc.close();
    if (scn != null) {
    scn.close();
    } catch (IOException ioe) {
    Client connects to server...server can send messages to server..but clients
    message does not reach server..that it cant be observed on server..how to debug jar file on mobile??

  • Send email from j2me through servlet

    Hi people,
    i hope you can help me because i am new in network programming.
    I am trying to send email from j2me to googlemail account I have 2 classes EmailMidlet (which has been tested with wireless Toolkit 2.5.2 and it works) and the second class is the servlet-class named EmailServlet:
    when i call the EmailServlet, i get on the console:
    Server: 220 mx.google.com ESMTP g28sm19313024fkg.21
    Server: 250 mx.google.com at your service
    this is the code of my EmailServlet
    import java.io.*;
    import java.net.Socket;
    import java.net.UnknownHostException;
    import java.text.*;
    import java.util.Date;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class EmailServlet extends HttpServlet {
       public void doPost(HttpServletRequest request, HttpServletResponse response)
             throws IOException, ServletException {
          System.out.println("____emailservlet.doPost");
          response.setContentType("text/plain");
          PrintWriter out = response.getWriter();
          System.out.println("______________________________");
          out.println();
          String to = request.getParameter("to");
          System.out.println("____________________________to" + to);
          String subject = request.getParameter("subject");
          String msg = request.getParameter("msg");
          // construct an instance of EmailSender
          System.out.println("servlet_to" + to);
          send("[email protected]", to, subject, msg);
          out.println("mail sent....");
       public void send(String from, String to, String subject, String msg) {
          Socket smtpSocket = null;
          DataOutputStream os = null;
          DataInputStream is = null;
          try {
             smtpSocket = new Socket("smtp.googlemail.com", 25);
             os = new DataOutputStream(smtpSocket.getOutputStream());
             is = new DataInputStream(smtpSocket.getInputStream());
          } catch (UnknownHostException e) {
             System.err.println("Don't know about host: hostname");
          } catch (IOException e) {
             System.err
                   .println("Couldn't get I/O for the connection to: hostname");
          if (smtpSocket != null && os != null && is != null) {
             try {
                os.writeBytes("HELO there" + "\r\n");
                os.writeBytes("MAIL FROM: " + from + "\r\n");
                os.writeBytes("RCPT TO: " + to + "\r\n");
                os.writeBytes("DATA\r\n");
                os.writeBytes("Date: " + new Date() + "\r\n"); // stamp the msg
                                                    // with date
                os.writeBytes("From: " + from + "\r\n");
                os.writeBytes("To: " + to + "\r\n");
                os.writeBytes("Subject: " + subject + "\r\n");
                os.writeBytes(msg + "\r\n"); // message body
                os.writeBytes(".\r\n");
                os.writeBytes("QUIT\r\n");
                // debugging
                String responseLine;
                while ((responseLine = is.readLine()) != null) {
                   System.out.println("Server: " + responseLine);
                   if (responseLine.indexOf("delivery") != -1) {
                      break;
                os.close();
                is.close();
                smtpSocket.close();
             } catch (UnknownHostException e) {
                System.err.println("Trying to connect to unknown host: " + e);
             } catch (IOException e) {
                System.err.println("IOException: " + e);
       } 1.when i print "to" in EmailServlet also:
      String to = request.getParameter("to");
          System.out.println("____________________________to" + to);  it show null on the console :confused:
    2. ist this right in case of googlemail.com?
      smtpSocket = new Socket("smtp.googlemail.com", 25);  I would be very grateful if somebody can help me.

    jackofall
    Please don't post in old threads that are long dead. When you have a question, please start a topic of your own. Feel free to provide a link to an old thread if relevant.
    I'm locking this thread now.
    db

  • [Request For Help] How To Send Email Midlet Using Secure Socket ?

    Hello, this is the first time i ask for help to forum.sun.com.
    i try to make secure connection for send email from MIDlet. Maybe you can check to my code :
    EmailMidlet.java
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.lcdui.;
    public class EmailMidlet extends MIDlet implements CommandListener{
    Display display = null;
    // email form fields
    TextField toField = null;
    TextField subjectField = null;
    TextField msgField = null;
    Form form;
    static final Command sendCommand = new Command("send", Command.OK, 2);
    static final Command clearCommand = new Command("clear", Command.STOP, 3);
    String to;
    String subject;
    String msg;
    public EmailMidlet() {
    display = Display.getDisplay(this);
    form = new Form("Compose Message");
    toField = new TextField("To:", "", 50, TextField.EMAILADDR);
    subjectField = new TextField("Subject:", "", 15, TextField.ANY);
    msgField = new TextField("MsgBody:", "", 90, TextField.ANY);
    public void startApp() throws MIDletStateChangeException {
    form.append(toField);
    form.append(subjectField);
    form.append(msgField);
    form.addCommand(clearCommand);
    form.addCommand(sendCommand);
    form.setCommandListener(this);
    display.setCurrent(form);
    public void pauseApp() {
    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    public void commandAction(Command c, Displayable d) {
    String label = c.getLabel();
    if(label.equals("clear")) {
    destroyApp(true);
    } else if (label.equals("send")) {
    to = toField.getString();
    subject = subjectField.getString();
    msg = msgField.getString();
    EmailClient client = new EmailClient(this,"[email protected]", to, subject, msg);
    client.start();
    }and EmailClient.java
    import javax.microedition.io.;
    import javax.microedition.lcdui.;
    import java.io.;
    import java.util.Date;
    public class EmailClient implements Runnable {
    private EmailMidlet parent;
    private Display display;
    private Form f;
    private StringItem si;
    private SecureConnection sc; //SSL
    private InputStream is;
    private OutputStream os;
    private String smtpServerAddress = "smtp.gmail.com"; //SSL
    String from;
    String to;
    String subject;
    String msg;
    public EmailClient(EmailMidlet m, String from, String to, String subject, String msg) {
    parent = m;
    this.from = from;
    this.to = to;
    this.subject = subject;
    this.msg = msg;
    display = Display.getDisplay(parent);
    f = new Form("Email Client");
    si = new StringItem("Response:" , " ");
    f.append(si);
    display.setCurrent(f);
    public void start() {
    Thread t = new Thread(this);
    t.start();
    public void run() {
    try {
    //SSL
    sc = (SecureConnection)
    Connector.open("ssl://"smtpServerAddress":465"); //smtp with SSL port 465
    sc.setSocketOption(SocketConnection.LINGER, 5);
    is = sc.openInputStream();
    os = sc.openOutputStream();
    os.write(("HELO there" "\r\n").getBytes());
    os.write(("EHLO" "\r\n").getBytes());
    os.write(("auth login" "\r\n").getBytes());
    os.write(("dHVnYXNha2hpci50cmlhZGl0eWFAZ21haWwuY29t" "\r\n").getBytes());
    os.write(("dGEuZW1haWxjbGllbnQ=" "\r\n").getBytes());
    os.write(("MAIL FROM:<">\r\n").getBytes());
    os.write(("RCPT TO:<">\r\n").getBytes());
    os.write("DATA\r\n".getBytes());
    // stamp the msg with date
    os.write(("Date: " new Date() "\r\n").getBytes());
    os.write(("From: "+from"\r\n").getBytes());
    os.write(("To: "to"\r\n").getBytes());
    os.write(("Subject: "subject"\r\n").getBytes());
    os.write((msg+"\r\n").getBytes()); // message body
    os.write(".\r\n".getBytes());
    os.write("QUIT\r\n".getBytes());
    StringBuffer sb = new StringBuffer();
    int ch = 0;
    while((ch = is.read()) != -1) {
    sb.append((char) ch);
    si.setText("SMTP server response - " + sb.toString());
    } catch(IOException e) {
    e.printStackTrace();
    Alert a = new Alert
    ("TimeClient", "Cannot connect to SMTP server. Ping the server to make sure it is running...", null, AlertType.ERROR);
    a.setTimeout(Alert.FOREVER);
    display.setCurrent(a);
    } finally {
    try {
    if(is != null) {
    is.close();
    if(os != null) {
    os.close();
    if(sc != null) {
    sc.close();
    } catch(IOException e) {
    e.printStackTrace();
    public void commandAction(Command c, Displayable s) {
    if (c == Alert.DISMISS_COMMAND) {
    parent.notifyDestroyed();
    parent.destroyApp(true);
    } When I try to debug project from netbeans, i found this error :
    Starting emulator in debug server mode on port 2668
    Connecting to 127.0.0.1 on port 2800
    nbdebug:
    Waiting for debugger on port 2668
    Waiting for KVM...
    Running with storage root temp.SonyEricsson_JP8_128x160_Emu10
    KdpDebugTask connecting to debugger 1 ..
    Running with locale: Indonesian_Indonesia.1252
    Connected to KVM
    Connection received.
    Attached JPDA debugger to localhost:2668
    java.io.IOException: error 10054 during TCP read +
    at com.sun.midp.io.j2me.socket.Protocol.nonBufferedRead(Protocol.java:299)+
    at com.sun.midp.io.BufferedConnectionAdapter.readBytes(BufferedConnectionAdapter.java:99)+
    at com.sun.midp.io.BaseInputStream.read(ConnectionBaseAdapter.java:582)+
    at com.sun.midp.ssl.Record.rdRec(+41)+
    at com.sun.midp.ssl.Record.rdRec(+5)+
    at com.sun.midp.ssl.In.refill(+18)+
    at com.sun.midp.ssl.In.read(+29)+
    at EmailClient.run(EmailClient.java:74)+
    Execution completed.
    5145824 bytecodes executed
    9258 thread switches
    1762 classes in the system (including system classes)
    0 dynamic objects allocated (0 bytes)
    0 garbage collections (0 bytes collected)
    debug:
    BUILD SUCCESSFUL (total time: 4 minutes 34 seconds)
    Regard
    Littlebro

    Don't multipost and don't use the browser's back button to edit your posts as that creates multiple postings. I've removed the other thread you started with the same questio.
    Also, don't post to long dead threads. I've blocked your post and locked the thread you resurrected.
    db

Maybe you are looking for

  • IChat Bonjour broken after 10.4.6 update

    After running the OS X 10.4.6 update yesterday, Bonjour suddenly stopped fucntioning properly in iChat. iChat with AIM buddies functions fine. But Bonjour tells me I'm all alone on the network -- even though other computers show up when I browse Netw

  • Some emails are not delivered, also not in LOG, no Bounce message

    I am Using Mountain lion server with the server app installed. Not the strange thing is that a lot email is not delevered to my email clients, but some are. The email that is having problems is [email protected] Does anybody know how to debug where th

  • Scanning to FTP

    Hi Guys, I am a remote worker that needs to be able to scan legal documents into my employers corporate data, my IT department dont like the idea of setting up a VPN from the local machine to gain access scans folder and being on a different network

  • Querry over pricing procedure used in creation of BIlling request

    Hi,      While creation of BIlling request via DP90 , system considers DIP Profile & pricing procedure and brings data /rates to billing procedure .. I am trying to understand the pricing procedure, i am using standard pricing procedure RVAA01 -> Whe

  • URGENT! PROBLEM WITH ADOBE FREE TRIAL PROGRAMS

    I created a new adobe id to renew my trial version of adobe programs but in adobe creative cloud it continues to inform me that i only have just 1 day to continue to use that programs. What should i do to start them from the first day?