Using SocketConnection and SecureConnection in J2ME to send emails.

Posted on 2007-07-24
Last Modified: 2013-11-24
I want to know if there's a big different If I use second parameter in the .open method of the Connector Class in j2me to open a connection. I was wondering if this helps in the communication between my client application and the server.

sc = (SocketConnection)"socket://" + smtpServerAddress + ":25");
sc = (SocketConnection)"socket://" + smtpServerAddress + ":25", Connector.WRITE);

Also I want to know if instead of SocketConnection I can use SecureConnection and what would be the difference ?
Can someone tell me how the secure connection really works ?
Question by:jonathan_otero
    LVL 5

    Expert Comment

    hi, this connection works fine and i have used it several time. Connector.WRITE is optional. u can simply ignore this paprameter. it will work fine. but if u wanna use this parameter then u must use, check it, there is a such parameter too. so that u can read and write data using this conection.

    but i recomend you to use simple 1 parameter and use abov conection.

    Kind Regards,
    LVL 12

    Accepted Solution

    SocketConnection is reurned by the when you try to send on a plain socket ["socket://" or "http://"]

    On the other hand, you get an instance of SecureConnection (which extends SocketConnection) if you send on a secure scoket using SSL ["ssl://" or "https://"]

    In case you want to use a secure connection - either https or ssl - you need to make sure that the server you are opening hte connection supports the same. You will also need to have the required certificates.

    Read up here for that :
    LVL 12

    Expert Comment

    gasitouch above has not given a proper explanation - its just something he/she does, not HOW and WHY it works!!

    The Connector can be opened in 3 modes - READ, WRITE, READ_WRITE

    An optional second parameter may be specified to the open function. This is a mode flag that indicates to the protocol handler the intentions of the calling code. The options here specify if the connection is going to be read (READ), written (WRITE), or both (READ_WRITE). The validity of these flag settings is protocol dependent. For instance, a connection for a printer would not allow read access, and would throw an IllegalArgumentException. If the mode parameter is not specified, READ_WRITE is used by default.

    So, when you dont specify any second parameter, it will take READ_WRITE by DEFAULT, so it works.

    There could be a case where the server MAY NOT allow the scoket to be opened in WRITE mode. In such cases, it may be necessary for you to specify the mode as READ.

    So above,

    sc = (SocketConnection)"socket://" + smtpServerAddress + ":25");
    results in the socket being opened in READ_WRITE mode

    sc = (SocketConnection)"socket://" + smtpServerAddress + ":25", Connector.WRITE);
    results in the socket being opened in WRITE_MODE

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now