Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix path for python3 and add a requirements.txt file #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ and their imdb rating when use chats with the server.

### How To Use It

Just run `make runserver` and it will start running the server on http://localhost:8888
```sh
mkvirtualenv chat -p $(which pythpn3)
pip install -r requirements.txt
python server.py
```

### Contact

Expand Down
2 changes: 1 addition & 1 deletion handlers/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MessageBuffer(object):
def __init__(self):
self.waiters = set()
self.cache = []
self.cache_size = 200
self.cache_size = 100000

def wait_for_messages(self, cursor=None):
result_future = Future()
Expand Down
2 changes: 1 addition & 1 deletion handlers/mainhandler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tornado.web
from buffer import MessageBuffer
from .buffer import MessageBuffer

global_message_buffer = MessageBuffer()

Expand Down
2 changes: 1 addition & 1 deletion handlers/newmessage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tornado.web
import uuid
import json
from buffer import MessageBuffer
from .buffer import MessageBuffer

global_message_buffer = MessageBuffer()

Expand Down
3 changes: 2 additions & 1 deletion handlers/routes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from handlers.mainhandler import MainHandler
from handlers.newmessage import MessageNewHandler
from handlers.updatemessage import MessageUpdatesHandler
from handlers.updatemessage import MessageUpdatesHandler, EchoWebSocket

route = [
(r"/", MainHandler),
(r"/a/message/new", MessageNewHandler),
(r"/websocket", EchoWebSocket),
(r"/a/message/updates", MessageUpdatesHandler),
]
15 changes: 13 additions & 2 deletions handlers/updatemessage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tornado.web
from buffer import MessageBuffer
from .buffer import MessageBuffer
from tornado import gen

from tornado.websocket import WebSocketHandler
global_message_buffer = MessageBuffer()


Expand All @@ -19,3 +19,14 @@ def post(self):

def on_connection_close(self):
global_message_buffer.cancel_wait(self.future)


class EchoWebSocket(tornado.websocket.WebSocketHandler):
def open(self):
print("WebSocket opened")

def on_message(self, message):
self.write_message(u"You said: " + message)

def on_close(self):
print("WebSocket closed")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tornado==4.5.3
1 change: 1 addition & 0 deletions serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def main():
xsrf_cookies=False,
debug=options.debug,
)
print("Server running at http://localhost:8888")
app.listen(options.port)
tornado.ioloop.IOLoop.current().start()

Expand Down