http://www.elabs.se/blog/66-using-websockets-in-native-ios-and-android-apps
Java-WebSocketを使う
https://github.com/TooTallNate/Java-WebSocket
gradle
dependencies { compile "org.java-websocket:Java-WebSocket:1.3.0" }
private void connectWebSocket() { URI uri; try { uri = new URI("ws://websockethost:8080"); } 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(); }