megZo
megZo

Reputation: 704

specify port on android device

i had asked a question earlier regarding android ports: How can my Android app open a port for listening?

i have a basic doubt in the method used to open a port. this is a line from my client code(the android app)

Socket socket = new Socket("10.112.73.105", 4444);

and 10.112.73.105 is the ip of my server.

afaik, this command opens port 4444 on the server for communication. is there any way to specify which port to use on the client android device?

Upvotes: 0

Views: 545

Answers (1)

raina77ow
raina77ow

Reputation: 106385

As described here, you can use the four-arguments Socket constructor:

public Socket(InetAddress address,
              int port,
              InetAddress localAddr,
              int localPort)

Here you can specify the localPort (localAddr apparently should be set to 127.0.0.1).

Upvotes: 2

Related Questions