Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* ************************************************************************
 #
 #  DivConq
 #
 #  http://divconq.com/
 #
 #  Copyright:
 #    Copyright 2014 eTimeline, LLC. All rights reserved.
 #
#  License:
#    See the license.txt file in the project's top-level directory for details.
#  Authors:
#    * Andy White
************************************************************************ */
package divconq.bus.net;
TODO cleanup for dc stuff Generates the demo HTML page which is served at localhost
public final class WebSocketServerIndexPage {
    private static final String NEWLINE = "\r\n";
    public static ByteBuf getContent(String webSocketLocation) {
        return Unpooled.copiedBuffer(
                "<html><head><title>Web Socket Test</title></head>" +  +
                "<body>" +  +
                "<script type=\"text/javascript\">" +  +
                "var socket;" +  +
                "if (!window.WebSocket) {" +  +
                "  window.WebSocket = window.MozWebSocket;" +  +
                '}' +  +
                "if (window.WebSocket) {" +  +
                "  socket = new WebSocket(\"" + webSocketLocation + "\");" +  +
                "  socket.onmessage = function(event) {" +  +
                "    var ta = document.getElementById('responseText');" +  +
                "    ta.value = ta.value + '\\n' + event.data" +  +
                "  };" +  +
                "  socket.onopen = function(event) {" +  +
                "    var ta = document.getElementById('responseText');" +  +
                "    ta.value = \"Web Socket opened!\";" +  +
                "  };" +  +
                "  socket.onclose = function(event) {" +  +
                "    var ta = document.getElementById('responseText');" +  +
                "    ta.value = ta.value + \"Web Socket closed\"; " +  +
                "  };" +  +
                "} else {" +  +
                "  alert(\"Your browser does not support Web Socket.\");" +  +
                '}' +  +
                 +
                "function send(message) {" +  +
                "  if (!window.WebSocket) { return; }" +  +
                "  if (socket.readyState == WebSocket.OPEN) {" +  +
                "    socket.send(message);" +  +
                "  } else {" +  +
                "    alert(\"The socket is not open.\");" +  +
                "  }" +  +
                '}' +  +
                "</script>" +  +
                "<form onsubmit=\"return false;\">" +  +
                "<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>" +
                "<input type=\"button\" value=\"Send Web Socket Data\"" +  +
                "       onclick=\"send(this.form.message.value)\" />" +  +
                "<h3>Output</h3>" +  +
                "<textarea id=\"responseText\" style=\"width:500px;height:300px;\"></textarea>" +  +
                "</form>" +  +
                "</body>" +  +
                "</html>" + .);
    }
    private WebSocketServerIndexPage() {
        // Unused
    }
New to GrepCode? Check out our FAQ X