Changed existing websocket examples to take a port

This commit is contained in:
Ben Ford
2010-09-29 07:16:32 +01:00
parent 0d4f448500
commit 64c065b3d1
2 changed files with 5 additions and 3 deletions

View File

@@ -5,7 +5,7 @@
<script> <script>
window.onload = function() { window.onload = function() {
var data = {}; var data = {};
var s = new WebSocket("ws://127.0.0.1:7000/chat"); var s = new WebSocket("ws://127.0.0.1:%(port)s/chat");
s.onopen = function() { s.onopen = function() {
s.send('New participant joined'); s.send('New participant joined');
}; };

View File

@@ -4,6 +4,8 @@ import eventlet
from eventlet import wsgi from eventlet import wsgi
from eventlet import websocket from eventlet import websocket
PORT = 7000
participants = set() participants = set()
@websocket.WebSocketWSGI @websocket.WebSocketWSGI
@@ -27,10 +29,10 @@ def dispatch(environ, start_response):
start_response('200 OK', [('content-type', 'text/html')]) start_response('200 OK', [('content-type', 'text/html')])
return [open(os.path.join( return [open(os.path.join(
os.path.dirname(__file__), os.path.dirname(__file__),
'websocket_chat.html')).read()] 'websocket_chat.html')).read() % PORT]
if __name__ == "__main__": if __name__ == "__main__":
# run an example app from the command line # run an example app from the command line
listener = eventlet.listen(('127.0.0.1', 7000)) listener = eventlet.listen(('127.0.0.1', PORT))
print "\nVisit http://localhost:7000/ in your websocket-capable browser.\n" print "\nVisit http://localhost:7000/ in your websocket-capable browser.\n"
wsgi.server(listener, dispatch) wsgi.server(listener, dispatch)