Permalink
Browse files

Chat server demo

  • Loading branch information...
drewlesueur committed Jan 27, 2010
1 parent fc5c7a9 commit bf48305b8849f05b02fae66f6259d398896f05f3
Showing with 23 additions and 12 deletions.
  1. +3 −1 handler.py
  2. +1 −1 index.html
  3. +10 −7 python-socket-server.py
  4. +8 −2 tick.py
  5. +1 −1 util.py
View
@@ -2,4 +2,6 @@
def handle(data, socko, to_read, to_write, to_error,scope):
util.ws_send(socko, scope.setdefault('last_message', ""))
- scope['last_message'] = data
+ scope['last_message'] = data
+ for write in to_write:
+ util.ws_send(write, data)
View
@@ -17,7 +17,7 @@
};
ws.onmessage = function (evt) {
var m = evt.data;
- console.log(m)
+ $('#message').after("<div class='message'>"+m+"</div>")
};
ws.onclose = function() {
alert("closed")
View
@@ -3,9 +3,14 @@
import time
import handler
import tick
-cycles_per_tick = 5000
+
+cycles_per_tick = 500
port = 5555
-hostname = socket.gethostname() #"127.0.0.1" #"192.168.1.104"
+hostname = hostname = socket.gethostname() #"127.0.0.1" #"192.168.1.104"
+
+
+
+
hostname = hostname.lower() #important
websocket_location = "/"
scope = {}
@@ -87,9 +92,7 @@ def closesocket(socko):
handle_data(data, socko, to_read, to_write, to_error)
except socket.error, msg:
closesocket(socko)
+ if counter % cycles_per_tick == 0:
+ tick.tick(socko, to_read, to_write, to_error, scope)
for socko in to_error:
- print socko + " had an error"
- for socko in to_write:
- if counter % cycles_per_tick == 0:
- print "tick"
- tick.tick(socko,scope)
+ print socko + " had an error"
View
10 tick.py
@@ -1,3 +1,9 @@
import util
-def tick(socko,scope):
- util.ws_send(socko, scope.setdefault("last_message", ""))
+import time
+
+def tick(socko, to_read, to_write, to_error, scope):
+ #do something
+ print "tick"
+ for socko in to_write:
+ #util.ws_send(socko, scope.setdefault("last_message", ""))
+ util.ws_send(socko, time.clock())
View
@@ -1,2 +1,2 @@
def ws_send(socko, message):
- socko.send('\x00' + message.encode('utf-8') + '\xff')
+ socko.send('\x00' + str(message).encode('utf-8') + '\xff')

0 comments on commit bf48305

Please sign in to comment.