0
我正在開發一個android應用程序,用於從android手機遠程控制PC。我設法開發了一個功能齊全的應用程序(客戶端和服務器(Java)應用程序),除了我必須爲客戶端指定要連接的IP。客戶端和服務器都在打開一個套接字並監聽端口8998.有沒有辦法獲得在特定端口上偵聽的服務器列表(在客戶端)?獲取在特定端口上偵聽的服務器列表android
謝謝你在前進,
克里斯蒂安
try {
InetAddress serverAddress = InetAddress.getByName(Constants.SERVER_IP); // getting the inet adress of the server
NetworkInterface netInterface = NetworkInterface.getByInetAddress(serverAddress); // getting the interface name where all other servers should be
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
for (InetAddress inetAddress : Collections.list(addresses)) {
out.println("InetAddress: " + inetAddress);
Log.d("adresses", String.valueOf(inetAddress));
}
}catch(IOException e){
Log.e("err", "Unknown hostname!");
}
謝謝你的回答!我或多或少的農場,我應該得到的結果,我真的只是與實施鬥爭..我編輯我的問題,並粘貼我試着與代碼,所以如果你可以幫助我,我會非常感謝。有了這個代碼我的應用程序崩潰,所以我真的不知道該怎麼做。 –
@ user3632600:「使用此代碼我的應用程序崩潰」 - 然後通過將'Exception'' e'作爲第三個參數傳遞給'Log.e()'來記錄實際的異常,而不是吃掉它。然後,使用LogCat檢查與您的崩潰相關的Java堆棧跟蹤。 – CommonsWare