2

我是套接字编程的新手。

我想在 Android 中连接到特定的 IP(例如:184.267.345.65)和端口(例如:53),这怎么可能呢?

提前致谢。

4

2 回答 2

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

有关完整的示例代码,请参见此处此处此处

于 2013-02-14T11:38:37.087 回答
-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();
}
于 2013-02-14T11:40:07.443 回答