我正在使用okhttp库连接我的本地WebSocket服务器(android应用程序)。
val request = Request.Builder().url("ws://localhost:3334/").build()
val wsClient = OkHttpClient().newWebSocket(request, webSocketListener)
Logger.log("WebSocketHandler", "${serialiser.toJson(wsClient.request())}")
和网络套接字侦听器
val webSocketListener = object : WebSocketListener() {
override fun onOpen(webSocket: WebSocket, response: Response) {
Logger.i("WebSocketListener_onOpen", "Response: ${serialiser.toJson(response)}")
}
override fun onMessage(webSocket: WebSocket, text: String) {
Logger.i("WebSocketListener_onMessage", "text: $text")
}
override fun onMessage(webSocket: WebSocket,
bytes: ByteString) {
Logger.i("WebSocketListener_onMessage", "text: ${serialiser.toJson(bytes)}")
}
override fun onClosing(webSocket: WebSocket,
code: Int, reason: String) {
Logger.i("WebSocketListener_onClosing", "reason: $reason, code: $code")
}
override fun onClosed(webSocket: WebSocket,
code: Int, reason: String) {
Logger.i("WebSocketListener_onClosed", "reason: $reason, code: $code")
}
override fun onFailure(webSocket: WebSocket,
throwable:Throwable,
response: Response?) {
Logger.i("WebSocketListener_onFailure", "Response: ${serialiser.toJson(throwable)}")
}
}
但是,当我尝试运行应用程序时,连接建立失败并显示日志
[socket]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
// throwable object
{
"cause": {
"cause": {
"errno": 111,
"stackTrace": [],
"suppressedExceptions": []
},
"detailMessage": "failed to connect to localhost/127.0.0.1 (port 3334) from /127.0.0.1 (port 49040) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)",
"stackTrace": [],
"suppressedExceptions": []
},
"detailMessage": "Failed to connect to localhost/127.0.0.1:3334",
"stackTrace": [],
"suppressedExceptions": []
}
onFailure甚至在建立连接之前就被调用了。WebSocket服务器工作正常(用nodeJS客户端单独测试)
我无法得到正确的错误信息。有人能帮我吗
1条答案
按热度按时间yyyllmsg1#
这是一个构建问题。文件系统/framework/mediatek-cta. jar不在jar中(或不在类路径上)