Skip to content

Testing in Android Emulator

Marcel Prestel edited this page Oct 2, 2018 · 1 revision

Please note Android Emulator has issues using IPv6 addresses. Executing any socket related code (like this library) inside it will address an error

java.net.SocketException: Bad address family

You have to manually disable IPv6 by calling

java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
java.lang.System.setProperty("java.net.preferIPv4Stack", "true");

somewhere in your project, before instantiating the WebSocketClient class. You can check if you are currently testing in the Android Emulator like this

if ("google_sdk".equals( Build.PRODUCT )) {
  // ... disable IPv6
}