Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send message from server to specific user #14

Open
ovoshlook opened this issue Jun 1, 2016 · 4 comments
Open

send message from server to specific user #14

ovoshlook opened this issue Jun 1, 2016 · 4 comments

Comments

@ovoshlook
Copy link

Hi is websocket have any way to send message from server to specific user
Like ws:send_text("some text",receiver_ip)?

@bungle
Copy link
Member

bungle commented Jun 1, 2016

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.

@ovoshlook
Copy link
Author

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?

@bungle
Copy link
Member

bungle commented Jun 1, 2016

@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).

@ouyangruoxue
Copy link

使用ngx.semaphore可以完成对应功能

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants