lua-resty-websocket
lua-resty-websocket copied to clipboard
send message from server to specific user
Hi is websocket have any way to send message from server to specific user Like ws:send_text("some text",receiver_ip)?
Each web socket connection is for specific user. And your server has these handles. You could set up a queue based on say REMOTE_ADDR etc. But I would use something that is unique to user. More than one user can share the same IP behind the NAT.
Thanks for reply. So am i right that i can get somewhere source IP of each user that connecting to websocket server like ngx.source_ip() or something like this?
@ovoshlook, of course, you may grap it from a normal nginx variable ngx.var.remote_addr
, but I wouldn't use it. You should at least check for reverse proxies, e.g.: https://github.com/bungle/lua-resty-session/blob/master/lib/resty/session.lua#L235-L252 (session module btw. doesn't check address by default because of many problems it might cause - but in a controlled environment, it is okay).
使用ngx.semaphore可以完成对应功能