Mercurial > hg > Members > riono > TreeVNC_ja_comment
changeset 201:ced24de3f2c5
get network interfaces.
author | oc |
---|---|
date | Fri, 27 Jun 2014 18:50:49 +0900 |
parents | 70af0b1b88d2 |
children | 22676ca0dd97 |
files | src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Fri Jun 27 17:20:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Fri Jun 27 18:50:49 2014 +0900 @@ -2,11 +2,18 @@ import java.io.IOException; import java.net.BindException; +import java.net.InetAddress; +import java.net.InterfaceAddress; +import java.net.NetworkInterface; import java.net.ServerSocket; import java.net.Socket; +import java.net.SocketAddress; +import java.net.SocketException; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.Enumeration; +import java.util.HashMap; import java.util.LinkedList; import java.util.concurrent.atomic.AtomicInteger; import java.util.zip.DataFormatException; @@ -58,6 +65,7 @@ private boolean hasViewer = false; private boolean reconnecting; private short reconnectingId; // Change Server Request to id's node VNC server + private HashMap<NetworkInterface, TreeManagement> interfaces = new HashMap<NetworkInterface, TreeManagement>(); public MyRfbProto() { @@ -276,6 +284,7 @@ servSock = new ServerSocket(port); acceptPort = port; myAddress = "127.0.0.1"; + getNetworkInterfaces(); break; } catch (BindException e) { port++; @@ -687,5 +696,20 @@ return reconnectingId; } + public void getNetworkInterfaces() throws SocketException { + for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) { + NetworkInterface ni; + ni = e.nextElement(); + if (ni.isUp() && ni.supportsMulticast() && !ni.isLoopback()) { + addNetworkInterface(ni, null); + System.out.println("Interfaces :" + ni.getName()); + } + } + } + + private void addNetworkInterface(NetworkInterface ni, TreeManagement treeManager) { + interfaces.put(ni, treeManager); + } + }