public void run()
        {
            running = true;

            while (running)
            {
                try
                {
                    IPEndPoint RemoteIPEndPoint = new IPEndPoint(IPAddress.Any, 1138);
                    Byte[]     receiveBytes     = udpClient.Receive(ref RemoteIPEndPoint);

                    HomeTransferServerData data = HomeTransferServerData.createFromUDP(receiveBytes);
                    if (data.type.Equals("close"))
                    {
                        HomeTransferModel.getInstance().removeServer(data);
                    }
                    else
                    {
                        HomeTransferModel.getInstance().addServer(data);
                        if (data.type.Equals("discover"))
                        {
                            HomeTransferController.getInstance().broadcastUDP("response");
                        }
                    }
                    HomeTransferController.getInstance().updateObserver();
                }
                catch (Exception e)
                {
                    Console.WriteLine("UDP listening finished.");
                }
            }
        }
Exemplo n.º 2
0
        public static void sendFiles(String server, String[] files)
        {
            // TODO: Get the selected remote instance's IP and start a sender thread
            String[] str = server.Split('@');
            String   IP  = str[1];
            HomeTransferServerData data   = HomeTransferModel.getInstance().getServerData(IP);
            HomeTransferClient     sender = new HomeTransferClient(data.IP, data.port, files);
            Thread senderThread           = new Thread(new ThreadStart(sender.run));

            senderThread.Start();
        }
        public static void broadcastPackage(String tag)
        {
            HomeTransferModel      model = HomeTransferModel.getInstance();
            HomeTransferServerData local = model.getLocalHomeTransferData();

            UdpClient udpClient = new UdpClient();

            udpClient.Connect("255.255.255.255", 1138);
            Byte[] senddata = Encoding.ASCII.GetBytes(local.name + ";" + local.IP + ";" + local.port + ";" + tag);
            udpClient.Send(senddata, senddata.Length);
        }
Exemplo n.º 4
0
        public Form1()
        {
            InitializeComponent();
            form1 = this;
            HomeTransferServerData local = HomeTransferModel.getInstance().getLocalHomeTransferData();

            this.Text = local.name + "@" + local.IP;
            this.listBox1.AllowDrop  = true;
            this.listBox1.DragDrop  += listBox1_DragDrop;
            this.listBox1.DragEnter += listBox1_DragEnter;
        }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            String         path = "";
            OpenFileDialog file = new OpenFileDialog();

            if (file.ShowDialog() == DialogResult.OK)
            {
                path = file.FileName;
            }
            String[] paths = new string[1];
            paths[0] = path;
            HomeTransferModel.getInstance().addFiles(paths);
        }
Exemplo n.º 6
0
 public void initController()
 {
     try
     {
         homeTransferServer    = new HomeTransferServer(HomeTransferModel.getInstance().getLocalHomeTransferData().port);
         homeTransferUDPServer = new HomeTransferUDPServer();
         serverThread          = new Thread(new ThreadStart(homeTransferServer.run));
         udpServerThread       = new Thread(new ThreadStart(homeTransferUDPServer.run));
         serverThread.Start();
         udpServerThread.Start();
     } catch (Exception e)
     {
         Console.WriteLine("Error: Server could not be created");
     }
 }
Exemplo n.º 7
0
        public void updateGUI()
        {
            listBox1.Invoke((MethodInvoker)(() => {
                listBox1.Items.Clear();
                String[] files = HomeTransferModel.getInstance().getFiles();
                foreach (String file in files)
                {
                    listBox1.Items.Add(file);
                }
            }));

            listBox2.Invoke((MethodInvoker)(() => {
                listBox2.Items.Clear();
                String[] servers = HomeTransferModel.getInstance().getServers();
                foreach (String server in servers)
                {
                    listBox2.Items.Add(server);
                }
            }));
        }
Exemplo n.º 8
0
        private void button3_Click(object sender, EventArgs e)
        {
            String server = "";

            if (listBox2.Items.Count > 1)
            {
                server = listBox2.GetItemText(listBox2.SelectedItem);
                if (server.Equals(""))
                {
                    MessageBox.Show("Please select a remote instance first");
                    return;
                }
            }
            else if (listBox2.Items.Count == 1)
            {
                server = listBox2.Items[0].ToString();
            }
            else
            {
                return;
            }
            HomeTransferController.sendFiles(server, HomeTransferModel.getInstance().getFiles());
        }
Exemplo n.º 9
0
 public void deleteFiles()
 {
     HomeTransferModel.getInstance().deleteFiles();
     updateObserver();
 }
Exemplo n.º 10
0
 public void refreshList()
 {
     HomeTransferModel.getInstance().deleteServers();
     broadcastUDP("discover");
     updateObserver();
 }
Exemplo n.º 11
0
 private void listBox1_DragDrop(object sender, DragEventArgs e)
 {
     string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
     HomeTransferModel.getInstance().addFiles(files);
 }