Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm working on a Java application that runs on both Windows and Mac. It communicates with various different servers but needs to behave differently depending whether it is using WiFi or a wired connection.

Is there anyway to work out which it is using?

I've looked at using NetworkInterface.getNetworkInterfaces() but that doesn't tell me which NetworkInterface is being used and whether it is WiFi or not.

share|improve this question

migrated from stackoverflow.com May 28 '13 at 1:13

This question came from our site for professional and enthusiast programmers.

    
Is the problem bandwidth? If yes, at launch time you may evaluate it to conclude: >250 MBps ==> network else WiFi –  Aubin May 24 '13 at 11:17
    
The problem is packet loss - the application uses UDP not TCP and I've found that the packet loss is much worse on Wi-Fi. –  tjlprice May 24 '13 at 11:23
add comment

2 Answers 2

up vote 0 down vote accepted

The only way to do this using native APIs.

These can be interfaced to from Java using JNA. On Mac, you'll need to use something like https://github.com/shannah/Java-Objective-C-Bridge on top of JNA to use the Objective-C framework.

share|improve this answer
add comment

With java.lang.ProcessBuilder you may execute ipconfig /all under Windows and /sbin/ifconfig -a under Linux (and Mac?) to answer the question "How am I connected to the network?".

To be more complete and accurate, you may enforce your protocol to add auto adaptive behavior: the quality, the bandwidth, the number of loss packets, and so on, allow you to decide how to drive your protocol.

You may use TCP/IP to drive the logic of the exchange (behavior, control) and use UDP for the data. First layer: UDP assumes discovery and data, second layer built on TCP to offer sessions management.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.