如何连接到特定的ip&在android中的端口

时间:2013-02-14 11:34:16

标签: java android sockets serversocket

我是套接字编程的新手。

我希望与特定的IP连接(例如:184.267.345.65)& Android中的端口(例如:53)所以怎么可能呢?

提前致谢。

2 个答案:

答案 0 :(得分:4)

Socket s = new Socket("184.267.345.65", 53)

有关完整的示例代码

,请参阅hereherehere

答案 1 :(得分:-2)

URLConnection connection = null;
URL url = null;
InputStream is = null;
String mUrl="IP ADDRESS AND PORT NUMBER";

try {
url = new URL(mUrl);

    connection = url.openConnection();
    connection.setRequestProperty("Accept", "SPECIFY ACCEPT TYPE");
is = connection.getInputStream();
String data=convertStreamToString(is);

} catch (Exception e) {
    Log.i("Exception while reading inputstream  From URL :"+mUrl, e.getMessage());
    e.printStackTrace();
}