Reputation: 9361
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;
Upvotes: 0
Views: 10379
Reputation: 7161
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.
Upvotes: 1
Reputation: 311050
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.
Upvotes: 0