Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nvThanh opened this issue Mar 9, 2021 · 1 comment
Open

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

nvThanh opened this issue Mar 9, 2021 · 1 comment

Comments

@nvThanh
Copy link

nvThanh commented Mar 9, 2021

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

@nvThanh
Copy link
Author

nvThanh commented Mar 9, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant