super(host, port);
DataInputStream din = new DataInputStream(inStream);
// Try to authenticate the remote agent
try {
String agentId = din.readUTF();
int sigLen = din.readInt();
byte[] sigData = new byte[sigLen];
din.readFully(sigData);
if (!authenticate(agentId, sigData)) {
// Failed to authenticate, write error message, close socket and
// return
System.out.println("Failed to authenticate remote agent " + agentId);
closeConnection();
}
else {
// Remote agent is authenticated, first message is a welcome
addMsg("HELLO " + agentId);
}
}
catch (Exception e) {
closeConnection();
}