
import data.DataBaseHelper;
import data.Log;
import data.SerialConnector;
import protobuf.RblProto;
import server.RBLSocketServer;
import server.RBLWebSocketServer;
import util.Config;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Created by Peter Mösenthin.
 *
 * Main class for the RaspberryLife server application.
 */
public class RaspberryLife {

    public static final String DEBUG_TAG = RaspberryLife.class.getSimpleName();
    public static Thread serverThread = null;
    public static Thread webServerThread = null;


    public static void main(String[] args){
        Log.add(DEBUG_TAG,"########### RaspberryLife server ###########");
        try {
            Log.add(DEBUG_TAG, "Starting RBLServer on IP: " +
                    InetAddress.getLocalHost().getHostAddress());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        // RaspberryHome WebSocketServer
        webServerThread = new Thread(new Runnable() {
            public void run() {
                Log.add(DEBUG_TAG,
                        "Starting WebSocketServer");
                RBLWebSocketServer webServer = new RBLWebSocketServer();
                webServer.start();
            }
        });

        // RaspberryHome Application Server
        serverThread = new Thread(new Runnable() {
            public void run() {
                Log.add(DEBUG_TAG, "Starting Java socket server");
                RBLSocketServer server = new RBLSocketServer();
                server.start(Config.JAVA_SOCKET_PORT);
            }
        });

        // Start threads
        webServerThread.start();
        serverThread.start();
        // Initialize the serial connector for module communication
        SerialConnector.init();
        DataBaseHelper.init();
        DataBaseHelper.closeConnection();
    }
}

@@ -225,36 +225,184 @@
 ava.net.
-UnknownHostException
+NetworkInterface;%0Aimport java.net.SocketException;%0Aimport java.net.UnknownHostException;%0Aimport java.util.ArrayList;%0Aimport java.util.Enumeration;%0Aimport java.util.List
 ;%0A%0A/**%0A 
@@ -832,227 +832,26 @@
     
-try %7B%0A            Log.add(DEBUG_TAG, %22Starting RBLServer on IP: %22 +%0A                    InetAddress.getLocalHost().getHostAddress());%0A        %7D catch (UnknownHostException e) %7B%0A            e.printStackTrace();%0A        %7D
+listIPAddresses();
 %0A%0A  
@@ -1285,32 +1285,36 @@
 ew Runnable() %7B%0A
+    
             publ
@@ -1321,32 +1321,32 @@
 ic void run() %7B%0A
-
                 
@@ -1803,16 +1803,1240 @@
 tion();%0A
-
     %7D
+%0A%0A    private static void listIPAddresses()%7B%0A        List%3CString%3E ipAddresses = new ArrayList%3CString%3E();%0A        int maxLength_ipv4 = 15;%0A        Enumeration e = null;%0A        //Get all network interfaces%0A        try %7B%0A            e = NetworkInterface.getNetworkInterfaces();%0A        %7D catch (SocketException e1) %7B%0A            e1.printStackTrace();%0A        %7D%0A%0A        //Check all network interfaces%0A        while(e!= null && e.hasMoreElements())%7B%0A            NetworkInterface n = (NetworkInterface) e.nextElement();%0A            Enumeration ee = n.getInetAddresses();%0A%0A            //Check all addresses in current interface%0A            while (ee.hasMoreElements())%7B%0A                InetAddress i = (InetAddress) ee.nextElement();%0A                String address = i.getHostAddress();%0A                if(address.length() %3C= maxLength_ipv4)%7B%0A                    if(!address.equals(%22127.0.0.1%22) && !address.equals(%220:0:0:0:0:0:0:1%22))%7B%0A                        //Log.address(DEBUG_TAG, %22RBLServer on machine: %22 + i.getHostAddress());%0A                        ipAddresses.add(address);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A%0A        Log.add(DEBUG_TAG, %22Server running on %22 + ipAddresses.toString());%0A    %7D%0A%0A
 %0A%7D%0A

Add ip address filtering