Mick
Mick

Reputation: 1219

Android client and server socket connection

Is it possible to make connection with server Mac Address using Socket or Do I need IP address of the server to setup the connection from client to server using Socket

socket = new Socket(serverAddr, SERVERPORT);

If I use IP address that change over the time so I don't want to use it. I want that remain same for the Android phone that seems Mac address to me.

Here both client and server is the Android Phone.

Upvotes: 1

Views: 1554

Answers (1)

mfsiega
mfsiega

Reputation: 2872

It sounds like you're trying to connect to the same device, even as it might be getting a new IP address?

MAC address is one way to do that. Per this blog post, you can read from /proc/net/arp and parse this information out, because Android is Linux-based. The MAC address-IP address mappings are stored in this file, and you can use the extracted IP address to do the Socket connect.

In general, you need an IP address to open a socket connection. Consider an analogy. Sending a packet over a socket is like sending a piece of mail to a street address. The IP address is the street address. If you don't know where your friend lives, you can't send her mail. If she moves, and doesn't tell you her new address, you can't send her more mail.

Upvotes: 1

Related Questions