allinurl / gwsocket

fast, standalone, language-agnostic WebSocket server RFC6455 compliant
http://gwsocket.io
MIT License
745 stars 67 forks source link

OpenBSD 5.9 - 400 Invalid Request #2

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hi,

I have no problem with the collection, but does not work

# gwsocket &
# vmstat -w 10 > /tmp/wspipein.fifo

lynx response is:

# lynx http://localhost:7890/terminal.html                                
Looking up localhost:7890
Making HTTP connection to localhost:7890
Sending HTTP request.
HTTP request sent; waiting for response.
Alert!: HTTP/1.1 400 Invalid Request
Data transfer complete

lynx: Start file could not be found or is not text/html or text/plain Exiting...

allinurl commented 8 years ago

I'm not sure I follow. The terminal.html file is a file you create and within it, you call the WebSocket() constructor. Let me know if the following question helps.

allinurl commented 8 years ago

Just to make things clear, here are the steps to send data from the server to the browser via websockets:

1.- First download gwsocket

$ wget http://tar.gwsocket.io/gwsocket-0.1.tar.gz
$ tar -xzvf gwsocket-0.1.tar.gz
$ cd gwsocket-0.1/
$ ./configure
$ make # make install

2.- Start the websocket server

    $ gwsocket &

3.- Send data from the server to the browser

    $ tail -f /var/log/apache2/access.log > /tmp/wspipein.fifo

4.- Then create an html file that connects to the server (make sure you are pointing to the right IP/host where the gwsocket server is running and the port is open):

<!DOCTYPE html>
<html lang="en">
<script>
window.onload = function() {
    function $(selector) {
        return document.querySelector(selector);
    }
    var socket = new WebSocket('ws://localhost:7890');
    socket.onopen = function(event) {
        $('#messages').innerHTML = 'Connected<br>';
    };
    socket.onmessage = function(event) {
        $('#messages').innerHTML += event.data + '<br>';
    };
    socket.onclose = function(event) {
        $('#messages').innerHTML = 'Disconnected ' + event.reason;
    };
};
</script>

<div id="page-wrapper">
    <pre id="messages">Connecting...</pre>
</div>

5.- Open the html file and you should see your data from the server in the browser.

ghost commented 8 years ago

Ok, did not understand what the terminal.html file.

Thank you, BR

allinurl commented 8 years ago

Closing this. Feel free to reopen it if needed.