HOME PCB
..CommandHandler.javaHost.java
package Program;

import Common.StaticValues;
import Communication.Messages.TCP.TCPMessageService;
import Communication.Messages.UDP.UDPMessageService;
import Multicast.MulticastJsonSendingThread;
import Multicast.MulticastWebProgram;

import java.awt.*;
import java.io.IOException;

public class Host
{
    public static void main(String[] args)
    {
        MulticastWebProgram webProgram = new MulticastWebProgram();
        webProgram.program_name = "DataView";
        webProgram.tcpPort = 8000;
        webProgram.udpPort = 4445;
        MulticastJsonSendingThread multicast = new MulticastJsonSendingThread<>(StaticValues.MulticastPort, StaticValues.MulticastAddress, StaticValues.MulticastIntervalMilli, webProgram);
        multicast.start();
        TCPMessageService tcp = null;
        UDPMessageService udp = null;
        HostFrame frame = new HostFrame();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        //frame.setSize(screenSize.width/2, screenSize.height/2);
        frame.pack();
        frame.setVisible(true);

        while (multicast.isAlive())
        {
            try
            {
                if (tcp == null || !tcp.isAlive())
                {
                    try
                    {
                        tcp = new TCPMessageService(webProgram.tcpPort);
                        tcp.start();
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }
                }


                if (udp == null || !udp.isAlive())
                {
                    try
                    {
                        udp = new UDPMessageService(webProgram.udpPort);
                        udp.start();
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }

                Thread.sleep(1000);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
}