use of jmri.server.json.JsonClientHandler in project JMRI by JMRI.
the class JsonServer method handleClient.
// Handle communication to a client through inStream and outStream
@Override
public void handleClient(DataInputStream inStream, DataOutputStream outStream) throws IOException {
ObjectReader reader = this.mapper.reader();
JsonClientHandler handler = new JsonClientHandler(new JsonConnection(outStream));
// Start by sending a welcome message
handler.onMessage(JsonClientHandler.HELLO_MSG);
while (true) {
try {
handler.onMessage(reader.readTree((InputStream) inStream));
// Read the command from the client
} catch (IOException e) {
// attempt to close the connection and throw the exception
handler.dispose();
throw e;
} catch (NoSuchElementException nse) {
// so break out of the loop
break;
}
}
handler.dispose();
}
Aggregations