Search in sources :

Example 1 with JsonClientHandler

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();
}
Also used : JsonClientHandler(jmri.server.json.JsonClientHandler) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) JsonConnection(jmri.server.json.JsonConnection) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 NoSuchElementException (java.util.NoSuchElementException)1 JsonClientHandler (jmri.server.json.JsonClientHandler)1 JsonConnection (jmri.server.json.JsonConnection)1