Subject: [hybi] Error in testing websockets !!!

From: vinod kumar <[email-masked]>
Date: Tue, 26 Jun 2012 12:23:57 +0200

Hi,

   I tried running a sample model. I started the server listening on a
port. I have a client in html file which connects to the websocket. But
when I start the client, it's giving me the following error. Someone,
please help me out.
---------------------------------------

'GET / HTTP/1.1\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nHost:
192.168.100.10:9997\r\nOrigin: null\r\nSec-WebSocket-Key:
95WQxAdZ0POM9hU6gR0oHQ==\r\nSec-WebSocket-Version: 13\r\n\r\n'
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "server.py", line 17, in handle
    s.send('\x00world\xff')
error: [Errno 32] Broken pipe
--------------------------------------

The comments on the website say :  The server is using the outdated
draft-74 protocol, whereas your version of Chrome is using probably draft-76

What does this mean? what exactly should I change in server and client
codes to make them work?

My server code is this :
--------------------------------------------------------
#!/usr/bin/env python

import socket, threading, time

def handle(s):
  print repr(s.recv(9998))
  s.send('''
HTTP/1.1 101 Web Socket Protocol Handshake\r
Upgrade: WebSocket\r
WebSocket-Origin: file:///home/vinodh/Desktop/homematic/e_notif/hws/\r
WebSocket-Location: ws://localhost:9876/\r
WebSocket-Protocol: sample
  '''.strip() + '\r\n\r\n')
  time.sleep(1)
  s.send('\x00hello\xff')
  time.sleep(1)
  s.send('\x00world\xff')
  s.close()

s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('192.168.100.10', 9997));
print 'binding done '
s.listen(1);
print 'listening '
while 1:
  t,_ = s.accept();
  print 'something got accepted '
  threading.Thread(target = handle, args = (t,)).start()
---------------------------------------------------
My Client code is this :
---------------------------------------------------
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Web Socket Example</title>
    <meta charset="UTF-8">
    <script>
      window.onload = function() {
        var s = new WebSocket("ws://192.168.100.10:9997/");
        s.onopen = function(e) { alert("opened"); }
        s.onclose = function(e) { alert("closed"); }
        s.onmessage = function(e) { alert("got: " + e.data); }
      };
    </script>
  </head>
    <body>
      <div id="holder" style="width:600px; height:300px"></div>
    </body>
</html>
--------------------------------------------------------------

Thanks,
Vinodh

---

From: vinod kumar <[email-masked]>
Date: Tue, 26 Jun 2012 12:25:22 +0200

And sorry, both are on localhost! The client code shows an ip. I edited it.