如何监听传入的tcp连接并在android中监听数据?

时间:2018-04-18 10:40:59

标签: android tcp

当我将请求发送到设备(硬件)但在收听tcp数据时没有得到响应时,我得到了响应

final Runnable r1 = new Runnable() {
            Socket listener;
            public void run() {
                try{
                    System.out.print("######## Thread Started######");

                    serverSocket = new ServerSocket(5555);

                    String message = null;
                    while(true){

                        listener = serverSocket.accept();
                        BufferedReader inFromServer = new BufferedReader(new InputStreamReader(listener.getInputStream()));
                        message = inFromServer.readLine();
                        System.out.println("*** Received message inside connection Thread"+message);

                    }

                }catch(Throwable e){
                    e.printStackTrace();
                }
                handler.postDelayed(this, 1000);
            }
        };

        handler.postDelayed(r1, 1000);

0 个答案:

没有答案