How to detect a remote side socket close? [duplicate]

The isConnected method won’t help, it will return true even if the remote side has closed the socket. Try this: public class MyServer { public static final int PORT = 12345; public static void main(String[] args) throws IOException, InterruptedException { ServerSocket ss = ServerSocketFactory.getDefault().createServerSocket(PORT); Socket s = ss.accept(); Thread.sleep(5000); ss.close(); s.close(); } } public class … Read more

How can I monitor the network connection status in Android?

Listen for CONNECTIVITY_ACTION This looks like good sample code. Here is a snippet: BroadcastReceiver networkStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.w(“Network Listener”, “Network Type Changed”); } }; IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(networkStateReceiver, filter);

How to configure a static IP address, netmask, gateway programmatically on Android 3.x or 4.x

I realise that there is no API on 3.x or 4.x for those setting per SSID. Therefore, I checked out the source code and found out that the configuration of each SSID is stored in android.net.wifi.WifiConfiguration which is gotten from android.net.wifi.WifiManager. In the below code, IpAssignment is an Enum, either STAIC, DHCP or NONE. And … Read more

How can I get the IP address from a NIC (network interface controller) in Python?

Two methods: Method #1 (use external package) You need to ask for the IP address that is bound to your eth0 interface. This is available from the netifaces package import netifaces as ni ip = ni.ifaddresses(‘eth0’)[ni.AF_INET][0][‘addr’] print(ip) # should print “192.168.100.37” You can also get a list of all available interfaces via ni.interfaces() Method #2 … Read more