但 Linux 系統預設的 fd_set size 只有 1024,若同時間處理的 fd 超過 1024 就會出問題
修改下面這兩個檔案,重新 build application 時就會引用到新的 define 值
/usr/include/bits/typesizes.h:
#define __FD_SETSIZE 1024
/usr/include/linux/posix_types.h:
#define __FD_SETSIZE 1024
#define __FD_SETSIZE 1024
#define __FD_SETSIZE 1024
// Models
company.models.Employee = Backbone.Model.extend({
defaults: {
id: undefined,
name: undefined
}
});
// Collections
company.collections.Department = Backbone.Collection.extend({
model: company.models.Employee
});
// Views
company.views.EmployeeList = Backbone.View.extend({
el: "#container",
render: function() {
...
}
});
// Create base data
var c = new company.collections.Department(
[{id:1, name: "Star Willard"},
{id:2, name: "Rhona Eggleston"},
{id:3, name: "Cassi Chowdhury"},
{id:4, name: "Leigh Nilson"},
{id:5, name: "Niesha Auger"}
]);
// Create view
var v = new company.views.EmployeeList({collection: c});
v.render();
import tornado.ioloop
import tornado.web
from tornado import websocket
class WSHandler(websocket.WebSocketHandler):
count = 0
def open(self):
print "Client connected"
def on_message(self, msg):
print "[%d] Got message [%s] from client" % (self.count, msg)
if self.count == 4:
self.close()
return
# Write back message
self.write_message("[%d] Echo: %s" % (self.count, msg))
self.count += 1
def on_close(self):
print "Client disconnected"
application = tornado.web.Application([
(r"/", WSHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
from tornado.websocket import websocket_connect
from tornado.ioloop import IOLoop
class ws_client():
conn = None # This is WebSocketClientConnection
def __init__(self):
websocket_connect('ws://localhost:8888/', callback=self.conn_cb)
def conn_cb(self, future):
self.conn = future.result()
self.conn.write_message("hello")
self.conn.read_message(self.read_cb)
def read_cb(self, future):
msg = future.result()
if msg is None:
print "Server disconnected"
IOLoop.instance().stop()
else:
print msg
self.conn.write_message("hello")
self.conn.read_message(self.read_cb)
if __name__ == '__main__':
ws_client()
IOLoop.instance().start()