Code example for Socket

Methods: close, connect, getOutputStream

0
    private static void sendCommand(String command, IDevice device, Window window, String params) {
        Socket socket = null;
        BufferedWriter out = null;
 
        try { 
            socket = new Socket();
            socket.connect(new InetSocketAddress("127.0.0.1",
                    DeviceBridge.getDeviceLocalPort(device)));
 
            out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
 
            out.write(command + " " + window.encode() + " " + params);
            out.newLine();
            out.flush();
        } catch (IOException e) {
            // Empty 
        } finally { 
            try { 
                if (out != null) {
                    out.close();
                } 
                if (socket != null) {
                    socket.close();
                } 
            } catch (IOException ex) {
                ex.printStackTrace();
            } 
        }