我为此http://192.168.0.6:8989/websocket URl在Android应用程序中尝试连接Web套接字,但没有得到任何响应,例如错误或成功。
我正在使用stomp网络套接字库,但未成功。
'''// connectWebSocket();
// Create a WebSocket factory and set 5000 milliseconds as a timeout
// value for socket connection.
WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(5000);
// Create a WebSocket. The timeout value set above is used.
try {
ws =factory.createSocket("http://192.168.0.6:8989/websocket");
ws.addListener(new WebSocketAdapter() {
@Override
public void onTextMessage(WebSocket websocket, String message) throws Exception {
Log.d("TAG", "onTextMessage: " + message);
}
});
ws.connectAsynchronously();
} catch (IOException e) {
e.printStackTrace();
}'''
编译'com.neovisionaries:nv-websocket-client:2.4'