Close
jGuru Forums
Posted By: Aitor_Zabaleta Posted On: Thursday, November 14, 2002 12:07 AM
Hi. I´m making a client/server application. The client will be in my Palm with J2ME, and the server, will be Java program in my laptop. How can I send data from the J2ME program to the server? Please, if you can, put here what function must I use or some sample code. Tank you very much.
Re: How can I send data from J2ME program?
Posted By: Bjornie_Wikstroem Posted On: Friday, November 15, 2002 01:45 PM
import java.io.*;import javax.microedition.io.*;public class CMail { private StreamConnection streamConnection; private InputStream inputStream; private OutputStream outputStream; private String[] mailParameters; public CMail( String subject, String message, String from, String to ) { String smtpServer = ""; try { smtpServer = "127.0.0.1"; } catch( Exception e ) { // error } try { this.streamConnection = ( StreamConnection ) Connector.open( "socket://" + smtpServer + ":25", Connector.READ_WRITE ); } catch( Exception e ) { // error } this.mailParameters = new String[ 5 ]; this.mailParameters[ 0 ] = "helo " + smtpServer; this.mailParameters[ 1 ] = "MAIL FROM:<" + from + ">"; this.mailParameters[ 2 ] = "RCPT TO:<" + to + ">"; this.mailParameters[ 3 ] = "DATA"; this.mailParameters[ 4 ] = "Subject: " + subject + "" + message + "."; } public void start() { try { this.inputStream = this.streamConnection.openDataInputStream(); this.outputStream = this.streamConnection.openOutputStream(); for( int i = 0; i < this.mailParameters.length; i++ ) { send( this.mailParameters[ i ] ); recive(); } this.inputStream.close(); this.outputStream.close(); this.streamConnection.close(); } catch( Exception e ) { // error } } private void send( String sendMe ) throws Exception { sendMe.concat( "" ); byte[] b = sendMe.getBytes(); this.outputStream.write( b ); this.outputStream.flush(); } private void recive() throws Exception { StringBuffer stringBuffer = new StringBuffer(); int character; while( ( character = this.inputStream.read() ) != -1 ) stringBuffer.append( ( char ) character ); }}
Posted By: Lasse_Koskela Posted On: Thursday, November 14, 2002 04:23 AM
javax.microedition.io