1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.util; |
2 |
> |
package uk.org.iscream.cms.server.util; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import java.net.*; |
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--- |
115 |
|
public void sendCommand(String cmd, int reply) throws IOException { |
116 |
|
_socketOut.println(cmd); |
117 |
|
String temp = _socketIn.readLine(); |
118 |
< |
if (!temp.startsWith(new Integer(reply).toString())) { |
118 |
> |
if (temp == null) { |
119 |
> |
throw new IOException ("IO error reading from socket, connection to server died?"); |
120 |
> |
} |
121 |
> |
if (!temp.startsWith(String.valueOf(reply))) { |
122 |
|
throw new IOException ("Expected " + reply + ", got " + temp); |
123 |
|
} |
124 |
|
} |
127 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
128 |
|
* method to provide clean logging (every class should have this). |
129 |
|
* |
130 |
< |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
130 |
> |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
131 |
|
* to format the toString() |
132 |
|
* |
133 |
|
* @return the name of this class and its CVS revision |
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 |
|
|