comparison src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 201:ced24de3f2c5

get network interfaces.
author oc
date Fri, 27 Jun 2014 18:50:49 +0900
parents b038aafeb2b0
children 22676ca0dd97
comparison
equal deleted inserted replaced
200:70af0b1b88d2 201:ced24de3f2c5
1 package jp.ac.u_ryukyu.treevnc; 1 package jp.ac.u_ryukyu.treevnc;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.net.BindException; 4 import java.net.BindException;
5 import java.net.InetAddress;
6 import java.net.InterfaceAddress;
7 import java.net.NetworkInterface;
5 import java.net.ServerSocket; 8 import java.net.ServerSocket;
6 import java.net.Socket; 9 import java.net.Socket;
10 import java.net.SocketAddress;
11 import java.net.SocketException;
7 import java.net.UnknownHostException; 12 import java.net.UnknownHostException;
8 import java.nio.ByteBuffer; 13 import java.nio.ByteBuffer;
9 import java.nio.ByteOrder; 14 import java.nio.ByteOrder;
15 import java.util.Enumeration;
16 import java.util.HashMap;
10 import java.util.LinkedList; 17 import java.util.LinkedList;
11 import java.util.concurrent.atomic.AtomicInteger; 18 import java.util.concurrent.atomic.AtomicInteger;
12 import java.util.zip.DataFormatException; 19 import java.util.zip.DataFormatException;
13 import java.util.zip.Deflater; 20 import java.util.zip.Deflater;
14 import java.util.zip.Inflater; 21 import java.util.zip.Inflater;
56 private TreeRootFinderListener getCast; 63 private TreeRootFinderListener getCast;
57 private CreateConnectionParam cp; 64 private CreateConnectionParam cp;
58 private boolean hasViewer = false; 65 private boolean hasViewer = false;
59 private boolean reconnecting; 66 private boolean reconnecting;
60 private short reconnectingId; // Change Server Request to id's node VNC server 67 private short reconnectingId; // Change Server Request to id's node VNC server
68 private HashMap<NetworkInterface, TreeManagement> interfaces = new HashMap<NetworkInterface, TreeManagement>();
61 69
62 70
63 public MyRfbProto() { 71 public MyRfbProto() {
64 rThread = new RequestScreenThread(this); 72 rThread = new RequestScreenThread(this);
65 } 73 }
274 while (true) { 282 while (true) {
275 try { 283 try {
276 servSock = new ServerSocket(port); 284 servSock = new ServerSocket(port);
277 acceptPort = port; 285 acceptPort = port;
278 myAddress = "127.0.0.1"; 286 myAddress = "127.0.0.1";
287 getNetworkInterfaces();
279 break; 288 break;
280 } catch (BindException e) { 289 } catch (BindException e) {
281 port++; 290 port++;
282 continue; 291 continue;
283 } catch (IOException e) { 292 } catch (IOException e) {
685 694
686 public int getReconnectingId() { 695 public int getReconnectingId() {
687 return reconnectingId; 696 return reconnectingId;
688 } 697 }
689 698
699 public void getNetworkInterfaces() throws SocketException {
700 for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
701 NetworkInterface ni;
702 ni = e.nextElement();
703 if (ni.isUp() && ni.supportsMulticast() && !ni.isLoopback()) {
704 addNetworkInterface(ni, null);
705 System.out.println("Interfaces :" + ni.getName());
706 }
707 }
708 }
709
710 private void addNetworkInterface(NetworkInterface ni, TreeManagement treeManager) {
711 interfaces.put(ni, treeManager);
712 }
713
690 714
691 } 715 }