public void send() throws IOException {
Socket socket = null;
PrintWriter out = null;
BufferedReader in = null;
socket = new Socket(host, portNumber);
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
Message m = new Message();
m.setStatus(status);
m.setCommand(command);
m.setQueueName(queueName);
m.setProcessingRule(processingRule);
m.setMessageId(messageId);
m.setPayload(payload);
//protocol stipulates that the the message
//length will be followed by a new line character
//which will be followed by the message
out.println(m.toString().length());
out.println(m.toString());
//read server's reply
StringBuffer sb = new StringBuffer();
String line = in.readLine();
while (line != null) {
sb.append(line);
line = in.readLine();
}
reply = new Message(sb.toString());
out.close();
in.close();
socket.close();
}