47 |
|
_socket = new Socket(server, port); |
48 |
|
_socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream())); |
49 |
|
_socketOut = new PrintWriter(_socket.getOutputStream(), true); |
50 |
< |
_socketIn.readLine(); // get 220 welcome header |
51 |
< |
sendCommand("HELO " + InetAddress.getLocalHost().getHostName(), 250); |
50 |
> |
init(); |
51 |
|
} |
52 |
|
|
53 |
|
//---PUBLIC METHODS--- |
140 |
|
} |
141 |
|
|
142 |
|
//---PRIVATE METHODS--- |
143 |
+ |
|
144 |
+ |
/** |
145 |
+ |
* Check the server sends a 220 message, and |
146 |
+ |
* then send our HELO. |
147 |
+ |
* |
148 |
+ |
* @throws IOException if something goes wrong |
149 |
+ |
*/ |
150 |
+ |
private void init() throws IOException { |
151 |
+ |
String temp = _socketIn.readLine(); |
152 |
+ |
// skip over any 220- lines |
153 |
+ |
while(temp != null && temp.startsWith("220-")) { |
154 |
+ |
temp = _socketIn.readLine(); |
155 |
+ |
} |
156 |
+ |
// check if we got a 220 welcome header |
157 |
+ |
if(temp == null || !temp.startsWith("220 ")) { |
158 |
+ |
throw new IOException ("Server did not initialise with a 220 message"); |
159 |
+ |
} |
160 |
+ |
// server gave a 220, it's ok to do a HELO |
161 |
+ |
sendCommand("HELO " + InetAddress.getLocalHost().getHostName(), 250); |
162 |
+ |
} |
163 |
|
|
164 |
|
//---ACCESSOR/MUTATOR METHODS--- |
165 |
|
|