Class HttpServerHelper


  • public class HttpServerHelper
    extends VertxHelperBase
    A helper class for the httpSocket module's Server object in JavaScript. Instances of this class are helpers for a server that can support multiple sockets. See the documentation of that module for instructions. This uses Vert.x for the implementation.
    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Edward A. Lee amd Elizabeth Osyk
    Pt.AcceptedRating:
    Red (bilung)
    Pt.ProposedRating:
    Yellow (eal)
    • Method Detail

      • closeServer

        public void closeServer()
        Close the web socket server. Note that this closing happens asynchronously. The server may not be closed when this returns.
      • convertImageBody

        public AWTImageToken convertImageBody​(java.lang.String body)
        Convert a string to an image token. If there is a problem then _error() is called.
        Parameters:
        body - The html to be converted.
        Returns:
        The ImageToken that is created.
      • getOrCreateServer

        public static HttpServerHelper getOrCreateServer​(java.lang.Object actor,
                                                         jdk.nashorn.api.scripting.ScriptObjectMirror currentObj,
                                                         java.lang.String hostInterface,
                                                         int port)
        Create a HttpServerHelper instance to help a JavaScript HttpServer instance.
        Parameters:
        actor - The actor associated with this helper.
        currentObj - The JavaScript HttpServer instance for which this is a helper.
        hostInterface - The host interface to use, in case there the host has more than one interface (e.g. Ethernet and WiFi). This is IP address or name, and if the argument is null, then "localhost" will be used.
        port - The port number that the server will use.
        Returns:
        A new HttpServerHelper instance.
      • respond

        public void respond​(int requestID,
                            java.lang.String responseText,
                            int responseCode)
        Respond to the request with the specified ID by sending the specified text.
        Parameters:
        requestID - The request ID.
        responseText - The text with which to respond.
        responseCode - The response code
      • startServer

        public void startServer()
        Create and start the server and beginning listening for requests. When a new request is received, call the _request() function of the associated JavaScript HttpServer object.