None.js

 http://shohei.yokoyama.ac/%E6%8A%80%E8%A1%93%E3%83%A1%E3%83%A2/node.js%E3%81%A7WebSocket%E3%82%B5%E3%83%BC%E3%83%90
https://github.com/Worlize/WebSocket-Node/wiki/Documentation

```shell:
cd /usr/local/src
wget http://nodejs.org/dist/v0.10.18/node-v0.10.18-linux-x86.tar.gz
tar zxvf node-v0.10.18-linux-x86.tar.gz
mv node-v0.10.18-linux-x86 /usr/local/node
/usr/local/node/bin/npm install -g websocket
easy_install websocket-client
```

```node.js
#!/usr/local/node/bin/node

var conn            = [];
var WebSocketServer = require('/usr/local/node/lib/node_modules/websocket').server;
var http            = require('http');
var originIsAllowed = function(){return true;}
var server          = http.createServer(function(request, response) {
                        console.log((new Date()) + ": Received request for " + request.url);
                        response.writeHead(404, {"Content-Type": 'text/plain'});
                        response.write('Page Not Found.');
                        response.end();
                      });

server.listen(8888, function() {
    console.log((new Date()) + ": Echo Server is listening on port 8888");
});

wsServer = new WebSocketServer({httpServer: server,
                                autoAcceptConnections: false});

wsServer.on('close', function(request) {
    console.log("Closed");
});

wsServer.on('request', function(request) {
    if (!originIsAllowed(request.origin)) {
        request.reject();
        console.log((new Date()) + ": Connection from origin " + request.origin + " rejected.");
        return;
    }
    console.log("Connected");
    var con = request.accept(null, request.origin)
    conn.push(con);
    con.on('message', function(mg) {
        console.log(mg);
        for(var c = 0;c < conn.length;c++){
            if(!conn[c].closed){
                conn[c].sendUTF("\t"+mg.utf8Data+"");
            }
        }
    });
});
```

```html:node.html
<!doctype html>
<html>
  <head>
    <title>node-websocket-server test</title>
  </head>
  <body>
    <div><input id="subject" type="textfield"/>
         <input id="message" type="textfield"/>
         <a href="#" id="send">Send</a>
    </div>
    <div id="msg_list" style="height:300px; overflow:auto;"></div>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">

        var host = "192.168.0.99";
        var port = 8888;
        var conn;
        var connect = function() {
          if (window["WebSocket"]) {
            conn = new WebSocket("ws://"+host+":"+port+"/");
            conn.onmessage = function(evt) {
                var data = JSON.parse(evt.data);
                $("#msg_list").prepend("<div class='msg'>" + data.message + " &gt; "+ data.message + "</div>");
            };

            conn.onerror = function() {
                $("#msg_list").prepend("<div class='msg'>Error</div>");
            };

            conn.onclose = function() {
                var data = JSON.stringify({subject: 'client', message: 'closed'});
                conn.send(message);
            };

            conn.onopen = function() {
                var data = JSON.stringify({subject: 'client', message: 'opend'});
                conn.send(message);
            };
          }
        };

        document.getElementById("send").addEventListener("click", function(e) {
          if (conn) {
            var subject = document.getElementById("subject").value;
            var message = document.getElementById("message").value;
            var data    = JSON.stringify({subject: subject,message: message});
            conn.send(data);
          }
          return false;
        }, false);

        window.onload = connect;
    </script>
  </body>
</html>
```


```py:client.py
import datetime
from websocket import create_connection

try:
ws = create_connection('ws://192.168.0.99:8888')
ws.send(datetime.datetime.now().strftime(u'%Y/%m/%d %H:%M:%S'))
```