Link to home
Start Free TrialLog in
Avatar of jonathan_otero
jonathan_otero

asked on

Using SocketConnection and SecureConnection in J2ME to send emails.

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 ?
Avatar of qasitouch
qasitouch
Flag of Pakistan image

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.
ASKER CERTIFIED SOLUTION
Avatar of keyurkarnik
keyurkarnik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of keyurkarnik
keyurkarnik

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