2012-10-24 46 views
3

我試圖打開從我的android應用程序到在Roving Networks WiFly上運行的服務器的TCP連接。按名稱android tcp連接

:當我連接使用的IP地址的連接打開正確的,但如果我連接使用主機名,然後我得到一個錯誤,因此我的路由器作爲主機WiFly上WiFly出現與192.168.1.4

的IP地址無法打開主機「wifly」:沒有與主機名

這裏相關的地址使用的代碼片段:

try 
    { 
     InetAddress serverAddr = InetAddress.getByName("wifly"); 

     Log.d("TCP Client", "C: Connecting..."); 

     //create a socket to make the connection with the server 
     Socket socket = new Socket(serverAddr, SERVERPORT); 

     ....... 
    } 

任何想法嗎?

回答

0

您應該檢查名稱是否正確 您可以使用從Oracle documentation

採取

import java.io.*; 
import java.net.*; 
import java.util.*; 
import static java.lang.System.out; 

public class ListNets { 

    public static void main(String args[]) throws SocketException { 
     Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); 
     for (NetworkInterface netint : Collections.list(nets)) 
      displayInterfaceInformation(netint); 
    } 

    static void displayInterfaceInformation(NetworkInterface netint) throws SocketException { 
     out.printf("Display name: %s\n", netint.getDisplayName()); 
     out.printf("Name: %s\n", netint.getName()); 
     Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); 
     for (InetAddress inetAddress : Collections.list(inetAddresses)) { 
      out.printf("InetAddress: %s\n", inetAddress); 
     } 
     out.printf("\n"); 
    } 
} 

代碼列出所有主機,看看實際的命名標識的,並使用它。

+0

我修改了代碼在我的android上運行,但結果是這 –

+0

結果是...? –