0

I am setting up a client and server software on two Android tablets using sockets programming. One Android tablet is the client and the other is the server.

In the sample code the author made the IP address and port number as shown below. What are my options for ports and IP addresses? If I choose a different port, what is the range of ports that I can use and what is the range of IP address I can use? That is if I don't want to use 10.0.2.15 for the IP and also use something different than 8080 as the port.

 // default ip
 public static String SERVERIP = "10.0.2.15";

 // designate a port
 public static final int SERVERPORT = 8080;
Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
Kevik
  • 9,181
  • 19
  • 92
  • 148
  • Simple, all ports below 1024 are reserved, apart from that u can use any between 1024 to 65534. @RDX is correct. – Siddharth Jan 22 '13 at 04:50

2 Answers2

1

Are both android tablets in same network? Because IP would be assigned by the network you are using. For example if you are behind a wifi router, then it must have assigned you an IP. For ports, There are 65534 distinct and usable port numbers

You need to find IP address of your phone as well, you may refer How to get IP address of the device from code? for programtically finding IP of your device.

Or refer http://www.techpaparazzi.com/how-to-find-ip-address-of-android-smartphone/ to find IP of your device.

Community
  • 1
  • 1
Rohit
  • 6,941
  • 17
  • 58
  • 102
  • 65535 actually. You can't use zero. Also several thousand of them are reserved by IANA. And he doesn't need to find the IP address of his own phone: the client phone needs the IP address of the server phone only, not the other way around, and neither needs its own address. – user207421 Jan 22 '13 at 05:39
0

You don't need to specify an IP address in the server. Just use INADDR_ANY. For available port numbers you need to research the assigned port numbers at the IANA Registry and use one that isn't assigned.

user207421
  • 305,947
  • 44
  • 307
  • 483