【问题标题】:netty-socketio server, how to handler socket.io client authentification request?netty-socketio 服务器,如何处理 socket.io 客户端认证请求?
【发布时间】:2014-08-28 01:46:05
【问题描述】:

我使用来自 github.com 的 netty-socketio 1.6.6 和 netty-socketio-demo

var socket =  io.connect('http://192.168.202.13:9092', {'username': 'ron', 'password': '1111'});

当我发送消息时,我可以在

中找到它
[nioEventLoopGroup-3-1] INFO com.corundumstudio.socketio.handler.PacketHandler - In message: 5:::{"name":"chatevent","args":[{"userName":"user470","message":"ssssssssss"}]} sessionId: 9c6f22f4-7d19-4632-ba50-4eb70b845a13

但是在连接时,我找不到'username': 'guo', 'password': '1111' [nioEventLoopGroup-3-1] INFO com.corundumstudio.socketio.handler.PacketHandler - In message: 2:: sessionId: 9c6f22f4-7d19-4632-ba50-4eb70b845a13.

我想做的是

1.认证。

2.向特定用户发送消息。

感谢您的帮助。

到目前为止,没有答案。慢慢地我意识到我把用户名和密码放在了错误的地方。 我需要编写一个 anthentification 事件来满足这个请求。 我对吗?

【问题讨论】:

    标签: java socket.io netty


    【解决方案1】:

    socketio 中的认证数据通过连接参数发送,如:

    http://192.168.202.13:9092/socketio/1/?username=ron&password=1111
    

    在你的 netty-socketio Configuration 对象中定义跟随参数:

        config.setAuthorizationListener(new AuthorizationListener() {
            @Override
            public boolean isAuthorized(HandshakeData data) {
                String username = data.getSingleUrlParam("username");
                String password = data.getSingleUrlParam("password");
                // if username and password correct
                   return true;
                // else
                   return false;
            }
        });
    

    【讨论】:

      猜你喜欢
      • 2013-05-13
      • 2022-12-08
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 2017-05-14
      • 2013-08-06
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多