Skip to content

Commit

Permalink
new websocket example and loseConnection fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Gleicon Moraes committed Mar 9, 2010
1 parent b535e2c commit e0d2591
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.so
*~
build
dist
cyclone.egg-info
4 changes: 2 additions & 2 deletions cyclone/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import urlparse
import uuid
import xmlrpclib


class RequestHandler(object):
"""Subclass this class and define get() or post() to make a handler.
Expand Down Expand Up @@ -842,7 +842,7 @@ def _execute(self, transforms, *args, **kwargs):
message = "Expected WebSocket Headers"
self.transport.write("HTTP/1.1 403 Forbidden\r\nContent-Length: " +
str(len(message)) + "\r\n\r\n" + message)
self.close()
self.transport.loseConnection()
else:
self.transport.write(
"HTTP/1.1 101 Web Socket Protocol Handshake\r\n"
Expand Down
5 changes: 3 additions & 2 deletions demos/websocket/websocket.tac
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# test: twistd -ny websocket.tac
# point your browser to http://localhost:8888


import cyclone.web
from twisted.application import service, internet


class MainHandler(cyclone.web.RequestHandler):
def get(self):
self.render("index.html")
self.render("interact.html")


class WebSocketHandler(cyclone.web.WebSocketHandler):
Expand All @@ -17,7 +18,7 @@ class WebSocketHandler(cyclone.web.WebSocketHandler):

def messageReceived(self, message):
self.sendMessage("echo: %s" % message)
self.transport.loseConnection()
# self.transport.loseConnection()

def connectionLost(self, why):
print "connection lost:", why
Expand Down

0 comments on commit e0d2591

Please sign in to comment.