wseemann / RoMote

Open source Roku remote. Turn your Android Device into a control center for your Roku Player and Roku TV.
Apache License 2.0
97 stars 27 forks source link

Can not find device even phone connect to same wifi network #21

Open nvThanh opened 3 years ago

nvThanh commented 3 years ago

The app pending at finding device ( other app take 1 sec to found device ),

nvThanh commented 3 years ago

private String scanForRoku(URL url) throws IOException { byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String MSEARCH = "M-SEARCH * HTTP/1.1\nHost: " + url.getHost() + ":" + url.getPort() + "\nMan: \"ssdp:discover\"\nST: roku:ecp\n"; sendData = MSEARCH.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, InetAddress.getByName(url.getHost()), url.getPort()); DatagramSocket clientSocket = new DatagramSocket(); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String response = new String(receivePacket.getData()); clientSocket.close(); response = response.toLowerCase(); String address = response.split("location:")[1].split("\n")[0].split("http://")[1].split(":")[0].trim(); return address; }

its stuck in here, maybe you run more than 1 thread at the same time