[:en]Example Code Application | VESTEL B2B Support Portal

[:en]Example Code Application

[:en]Example Code Application

Get socket message

new Thread(new Runnable() {

    @Override

    public void run() {

        Log.i(TAG, "get socket message");

        try {

            ServerSocket serverSocket = new ServerSocket(1987);

            while (!Thread.currentThread().isInterrupted()) {

                String msg = null;

                Socket socket = serverSocket.accept();

                if (socket != null) {

                    BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));

                    while ((msg = input.readLine()) != null) {

                        Log.i("TESTTOOL msg is ", msg);

                    }

                }

            }

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

}).start();
Send socket message

new Thread(new Runnable() {

    @Override

    public void run() {

        try {

            Log.i(TAG, "send socket message");

            Socket socket = new Socket("localhost", 1986);

            DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());

            byte[] bytes = new String("SETMUTE").getBytes();

            outputStream.write(bytes);

            outputStream.flush();

            outputStream.close();

            socket.close();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}).start();