Skip to content

Instantly share code, notes, and snippets.

@sassembla
Created March 8, 2015 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sassembla/fb238325d1bcd32992e2 to your computer and use it in GitHub Desktop.
Save sassembla/fb238325d1bcd32992e2 to your computer and use it in GitHub Desktop.
nginx + lua で複数クライアント接続での合同contextみたいなやつ
--[[]
ゲームとか書けるところ。あとコンテキストの名の通り、データベースに依存せずにパラメータとか持てるぞ。
]]
local M = {}
function M.onConnect(from, publish)
ngx.log(ngx.ERR, "connect from:", from)
end
function M.onMessage(from, data, publish)
-- do something here.
ngx.log(ngx.ERR, "message from:", from, " data:", data)
-- publish(data, to)
-- publish(data, to1, to2, ,,,)
-- publish(data)
publish(data)
end
function M.onDisconnect(from, reason, publish)
ngx.log(ngx.ERR, "disconnect from:", from, " reason:", reason)
end
-- 100f/secくらい、ただし、すべてのルームが同期で動く。
function M.onFrame(publish)
end
return M
@sassembla
Copy link
Author

https://github.com/sassembla/nginx-luajit

ここから実装をCとかC++だけに持っていく。今は起動通信が一発必要なので、そのへんの自動化とか。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment