Java Networking Question

February 16, 2009 at 21:31:14
Specs: Microsoft Windows XP Professional, 2.999 GHz / 3582 MB
I'm trying to write a program that works with SMTP protocol for a class project. I can get the connection to the server set up fine and get the correct input code for the first response from the server. I am using a BufferedReader and readLine to get information back from the socket. The second time I try and call readLine the entire program freezes. Once I send the HELO <server> command to the server it is supposed to respond, I never receive that response back. Any suggestions?
Thanks,
Nick

PS. wrote a different network program and ran into same problem, got around it by creating a new socket every time I wanted to send something. Trying to use 1 socket this time.


See More: Java Networking Question

Report •


#1
February 17, 2009 at 02:49:10
Suggestions:

1. Try and telnet to the SMTP server, then you can experiment by typing the commands and seeing exactly what you need to type (and how many carriage returns you need to send) before it responds.

2. Perhaps your particular SMTP server is fussy and requires each line to be ended by CR LF character sequence, and you are only sending an LF character?
(CR=carriage return, LF=linefeed)

3. If you are confident enough with threading, do the reading from the socket and the writing to the socket in separate threads, then you don't need to worry about your application locking up just because it's waiting for input.


Report •

#2
February 17, 2009 at 07:52:24
Thanks for the reply.
"1. Try and telnet to the SMTP server, then you can experiment by typing the commands and seeing exactly what you need to type (and how many carriage returns you need to send) before it responds." - I've actually already been doing this but it is a good suggestion. With SMTP there is only the carriage return after the line, and maybe a double CR at the end of the data section.

"2. Perhaps your particular SMTP server is fussy and requires each line to be ended by CR LF character sequence, and you are only sending an LF character?" - This may be more along the lines of what is wrong, I will give this a shot, would the correct java command be "\n" or is there a different one when dealing with servers?

"3. If you are confident enough with threading, do the reading from the socket and the writing to the socket in separate threads, then you don't need to worry about your application locking up just because it's waiting for input." - I'm not to extremely confident with threading, but for this project a base code was given that I needed to fill in and that did not contain any threads.

This problem may be within the Buffered Reader itself, because before I wasn't able to write/read lines until the connection was closed. I will give 2 a shot and report back.
Thank you,
Nick


Report •

#3
February 17, 2009 at 08:19:41
Thanks again for the reply. I gave the "\n" a try and it worked great. Thanks so much for the suggestions.
Nick

Report •

Related Solutions


Ask Question