Class WebSocketServerHelper


  • public class WebSocketServerHelper
    extends VertxHelperBase
    A helper class for the webSocketServer and browser modules' Server object in JavaScript. Instances of this class are helpers for a server that can support multiple sockets and also responds to HTTP GET and POST requests. See the documentation of those modules for instructions. This uses Vert.x for the implementation.
    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Hokeun Kim and Edward A. Lee
    See Also:
    WebSocketHelper
    Pt.AcceptedRating:
    Red (bilung)
    Pt.ProposedRating:
    Yellow (eal)
    • Method Detail

      • addResource

        public void addResource​(java.lang.String path,
                                java.lang.Object resource,
                                java.lang.String contentType)
        Add a resource to be served by the server.
        Parameters:
        path - The path to the resource.
        resource - The resource to serve upon a request for this path.
        contentType - The content type.
      • closeServer

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

        public static WebSocketServerHelper createServer​(java.lang.Object actor,
                                                         jdk.nashorn.api.scripting.ScriptObjectMirror currentObj,
                                                         java.lang.String hostInterface,
                                                         boolean sslTls,
                                                         java.lang.String pfxKeyCertPassword,
                                                         java.lang.String pfxKeyCertPath,
                                                         int port,
                                                         java.lang.String receiveType,
                                                         java.lang.String sendType)
        Create a WebSocketServerHelper instance to help a JavaScript Server instance.
        Parameters:
        actor - The actor associated with this helper.
        currentObj - The JavaScript Server 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.
        sslTls - Whether SSL/TLS is enabled. This defaults to false.
        port - The port number that the server will use.
        pfxKeyCertPassword - The password to open the file specified in pfxKeyCertPath.
        pfxKeyCertPath - The path of the file that stores the private key and certificate in PFX (PKCS#12) format for the server.
        receiveType - The type to assume for incoming messages.
        sendType - The type for outgoing messages.
        Returns:
        A new WebSocketServerHelper instance.
      • setResponse

        public void setResponse​(java.lang.String response)
        Set the response.
        Parameters:
        response - The response.
      • startServer

        public void startServer()
        Create and start the server and beginning listening for connections. When a new connection request is received and a socket has been opened, emit the 'connection' event with the socket as an argument.