I think I solved the problem - it seems to have something to do with the StringBuffer, as the initial size is only 16 characters.
I added sb.ensureCapacity(100); - now it seems to work.
Main Topics
Browse All TopicsHi all,
I've created a midlet which also should send and receive Emails via SocketConnections (I'm using a Sony Ericsson P900 with MIDP 2.0 and GPRS-Connection).
While sending and receiving emails works in the emulator, it doesn't on the mobile. It seems he doesn't leave the while-loop (Reading InputStream).
I send a quit command in both cases, but somehow the InputStream doesn't seem to end...i have no more ideas. Would be great if anyone could help me - would be urgent!
The code for sending and receiving emails is the following:
public void sendEmail() {
try {
sc = (SocketConnection) Connector.open("socket://"
is = sc.openInputStream();
os = sc.openOutputStream();
sb = new StringBuffer();
// Send SMTP-Commands
os.write(("HELO" + domain + "\r\n").getBytes());
os.write(("MAIL FROM: "+ from_emailAdress +"\r\n").getBytes());
os.write(("RCPT TO: "+ to_emailAdress + "\r\n").getBytes());
os.write("DATA\r\n".getByt
os.write(("Date: " + new Date() + "\r\n").getBytes());
os.write(("From: "+ from_emailAdress +"\r\n").getBytes());
os.write(("To: "+ to_emailAdress +"\r\n").getBytes());
os.write(("Subject: MIAM TEST\r\n").getBytes());
os.write(("TESTMESSAGE FROM MIAM \r\n").getBytes());
os.write(".\r\n".getBytes(
os.write("QUIT\r\n".getByt
int c = 0;
// DOESN'T LEAVE LOOP
while ( (c = is.read() ) != -1) {
sb.append( (char)c);
}
System.out.println(sb.toSt
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if(is != null) {
is.close();
}
if(os != null) {
os.close();
}
if(sc != null) {
sc.close();
}
} catch(IOException e) {
e.printStackTrace();
}
}
}
public void getEmail() {
try {
sc = (SocketConnection) Connector.open("socket://"
is = sc.openInputStream();
os = sc.openOutputStream();
sb = new StringBuffer();
int ch = 0;
os.write( ("USER " + userName + "\r\n").getBytes());
os.write( ("PASS " + userPass + "\r\n").getBytes());
os.write( ("LIST" + "\r\n").getBytes());
os.write( ("RETR 1" + "\r\n").getBytes());
os.write("QUIT\r\n".getByt
while ( (ch = is.read() ) != -1) {
sb.append( (char) ch);
}
System.out.println(sb.toSt
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if(is != null) {
is.close();
}
if(os != null) {
os.close();
}
if(sc != null) {
sc.close();
}
} catch(IOException e) {
e.printStackTrace();
}
}
}
Regards,
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
;-)
Post a 0 point question in the Support topic area (http://www.experts-exchan
Business Accounts
Answer for Membership
by: jimmackPosted on 2004-08-16 at 02:46:37ID: 11808389
Are the reads/writes running within their own threads?
Are you sure that the loop is being reached (eg. does the output stream need flushing when the last data has been written)?