Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed python implementation

commit 5321eecf185543b0e20f4692616d4ceb0577a63c 1 parent cf22448
MWILLIAMS authored
Showing with 14 additions and 4 deletions.
  1. +14 −4 wsocket.py
View
18 wsocket.py
@@ -16,18 +16,28 @@ def start_server():
while True:
interact(csock, tick)
tick+=1
+
+
+def send_data(client, str):
+ #_write(request, '\x00' + message.encode('utf-8') + '\xff')
+ str = '\x00' + str.encode('utf-8') + '\xff'
+ return client.send(str)
+def recv_data(client, count):
+ data = client.recv(count)
+ return data.decode('utf-8', 'ignore')
def handshake(client, tick):
our_handshake = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n"+"Upgrade: WebSocket\r\n"+"Connection: Upgrade\r\n"+"WebSocket-Origin: http://localhost:8888\r\n"+"WebSocket-Location: "+" ws://localhost:1234/websession\r\n\r\n"
- shake = client.recv(255)
+ shake = recv_data(client, 255)
print shake
+ #We want to send this without any encoding
client.send(our_handshake)
def interact(client, tick):
- data = client.recv(255)
+ data = recv_data(client, 255)
print 'got:%s' %(data)
- client.send("clock ! tick%d\r\n" % (tick))
- client.send("out ! recv\r\n")
+ send_data(client, "clock ! tick%d" % (tick))
+ send_data(client, "out ! %s" %(data))
if __name__ == '__main__':
start_server()
Please sign in to comment.
Something went wrong with that request. Please try again.