2

I am new in socket programming.

I want to get connected to particular IP (e.g.: 184.267.345.65) & port (e.g.: 53) in Android so how could it be possible?

Thanks in advance.

Stijn Geukens
  • 15,454
  • 8
  • 66
  • 101
user2071791
  • 29
  • 1
  • 2
  • possible duplicate of [Example: Android bi-directional network socket using AsyncTask](http://stackoverflow.com/questions/5135438/example-android-bi-directional-network-socket-using-asynctask) – SztupY Feb 15 '13 at 11:20

2 Answers2

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

See here, here and here for complete example code

Community
  • 1
  • 1
iTech
  • 18,192
  • 4
  • 57
  • 80
-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();
}
Manish Lomte
  • 329
  • 4
  • 17
  • 1
    This is more suitable to connect to a server via `HTTP` requests **not** for socket communication – iTech Feb 14 '13 at 11:42