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."); } } }
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); }
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; }
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); }
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"); } }
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); } })); }
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()); }
public void deleteFiles() { HomeTransferModel.getInstance().deleteFiles(); updateObserver(); }
public void refreshList() { HomeTransferModel.getInstance().deleteServers(); broadcastUDP("discover"); updateObserver(); }
private void listBox1_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); HomeTransferModel.getInstance().addFiles(files); }