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

大佬,请问websocket无法连接是怎么回事呢? #9

Open
TangStudio opened this issue Aug 10, 2022 · 2 comments
Open

大佬,请问websocket无法连接是怎么回事呢? #9

TangStudio opened this issue Aug 10, 2022 · 2 comments

Comments

@TangStudio
Copy link

androidServer
.websocket("ws://${localIPAddress}:${port}/ws", object : SocketListener {
override fun onMessageResponseServer(msg: String, ChannelId: String) {
Log.e("WebSocketService", "msg = $msg")
}

            override fun onChannelConnect(channel: Channel) {
                val insocket = channel.remoteAddress() as InetSocketAddress
                val clientIP = insocket.address.hostAddress
                Log.e("WebSocketService", "connect client: $clientIP")

            }

            override fun onChannelDisConnect(channel: Channel) {
                val ip = channel.remoteAddress().toString()
                Log.e("WebSocketService", "disconnect client: $ip")
            }

        })
        .start()

我是这样写的,localIPAddress是用的你库里边的工具类,端口写的8080,然后AS查看日志,一直报disconnect client: /127.0.0.1:xxxx,
端口号一直在变化

@fengzhizi715
Copy link
Owner

客户端连这个地址:ws://${localIPAddress}:${port}/ws
带上最后的 /ws

@TangStudio
Copy link
Author

我的第一条评论的写法是服务端的写法,客户端是一个网页,那个ip和端口该怎么写呢

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

2 participants