[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using SocketConnection and SecureConnection in J2ME to send emails.

Posted on 2007-07-24
3
Medium Priority
?
1,197 Views
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) Connector.open("socket://" + smtpServerAddress + ":25");
sc = (SocketConnection) Connector.open("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 ?
0
Comment
Question by:jonathan_otero
  • 2
3 Comments
 
LVL 5

Expert Comment

by:qasitouch
ID: 19562984
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 conector.read/write, 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,
qasitouch.
0
 
LVL 12

Accepted Solution

by:
keyurkarnik earned 1500 total points
ID: 19608453
SocketConnection is reurned by the Connector.open 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 :
http://www.ibm.com/developerworks/wireless/library/wi-jio/
0
 
LVL 12

Expert Comment

by:keyurkarnik
ID: 19608507
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) Connector.open("socket://" + smtpServerAddress + ":25");
results in the socket being opened in READ_WRITE mode

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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month19 days, 19 hours left to enroll

873 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