I am developing an Android client for a server where the requirement is continuous exchange of audio stream to the WebSockets-based server.
While connection with web sockets the android client throws the following error.
Closed draft org.java_websocket.drafts.Draft_10@b2fe9b40 refuses handshake
But I tried with following web socket uri. Connection getting succeeded. ws://echo.websocket.org
Code:
URI uri;
try {
// uri = new URI(
// "ws://echo.websocket.org");
uri = new URI(
"ws://serverIP:9090/WebRtc/serverendpoint");
} catch (URISyntaxException e) {
e.printStackTrace();
return;
}
mWebSocketClient = new WebSocketClient(uri) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
Log.i("Websocket", "Opened");
mWebSocketClient.send("Hello from " + Build.MANUFACTURER + " "
+ Build.MODEL);
}
@Override
public void onMessage(String s) {
final String message = s;
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView textView = (TextView) findViewById(R.id.messages);
textView.setText(textView.getText() + "n" + message);
}
});
}
@Override
public void onClose(int i, String s, boolean b) {
Log.i("Websocket", "Closed " + s);
}
@Override
public void onError(Exception e) {
Log.i("Websocket", "Error " + e.getMessage());
}
};
mWebSocketClient.connect();
I tried the echo test from browser for the web socket(ws://serverIP:9090/WebRtc/serverendpoint) I have used. It's getting connected properly. But When I try that from both mobile or emulator, nothing works.
Please help me on this.
Aucun commentaire:
Enregistrer un commentaire