static void Main(string[] args) { int port = NetworkEnv.GetAvailableUdpPort(); client = new UdpClient(port); //client = new UdpClient(); IPEndPoint from = new IPEndPoint(0, 0); byte[] buffer = new byte[1]; string message; Console.WriteLine("start:" + port); Console.WriteLine(); do { Console.WriteLine("wait.."); buffer = client.Receive(ref from); message = GetMessage(buffer); printIPE(from); Console.WriteLine("\t" + message); Console.WriteLine(); }while (!string.IsNullOrEmpty(message) && !message.Equals("exit")); Console.WriteLine(); Console.WriteLine("App quit cause exit recived. any key to esc"); Console.ReadKey(); }
private static void TestOpenFile() { var port = NetworkEnv.GetAvailableUdpPort(); IPEndPoint server = null; UnicClient client = null; client = new UnicClient(port, (dat, ep) => { var str = Encoding.UTF8.GetString(dat); if (str.StartsWith("reg#")) { int _port = int.Parse(str.Remove(0, 4)); Console.WriteLine("register: " + _port); server = new IPEndPoint(IPAddress.Parse("127.0.0.1"), _port); FBCMD cmd = new FBCMD() { cmd = FBCMDString.OpenFile, uid = "f6we541f6we41", parm = new[] { "图像文件|*.png" } }; client.SendMessage(server, cmd.ToString()); } else if (str.StartsWith("rev#")) { Console.WriteLine("rev\t" + str.Remove(0, 4)); } else if (str.StartsWith("msg#")) { Console.WriteLine("msg\t" + str.Remove(0, 4)); } else { Console.WriteLine(str); } }); Console.WriteLine("Clien has init"); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "FileBrowser.exe"; startInfo.Arguments = port.ToString(); var p = Process.Start(startInfo); //准备工作完成;开始发送cmd Console.WriteLine(); while (p.HasExited == false) { if (Console.ReadKey().Key == ConsoleKey.Escape) { p.Kill(); break; } Thread.Sleep(10); } Console.WriteLine(); Console.WriteLine(p.ExitCode); Console.WriteLine("console end"); Console.ReadKey(); }
private static void ProcessGetFiles() { var port = NetworkEnv.GetAvailableUdpPort(); UnicClient client = null; Process p = null; client = new UnicClient(port, (dat, ep) => { var str = Encoding.UTF8.GetString(dat); if (str.StartsWith("rev#")) { Console.WriteLine("rev\t" + str.Remove(0, 4)); } else if (str.StartsWith("msg#")) { Console.WriteLine("msg\t" + str.Remove(0, 4)); } else { Console.WriteLine(str); } if (p?.HasExited == false) { p?.Kill(); } }); //ThreadTag(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "FileBrowser.exe"; startInfo.Arguments = getOpenFileArgs(true, "|*.png;*.jpg", port); p = Process.Start(startInfo); //TestOpenFile(); Console.WriteLine("line1"); while (p.HasExited == false) { Thread.Sleep(100); } client.Dispose(); Console.WriteLine("finished"); }
private void precheck() { Port = NetworkEnv.GetAvailableUdpPort(); client = new UdpClient(Port); }
static int Main(string[] args) { var localIp = IPAddress.Parse("127.0.0.1"); if (!int.TryParse(args[0], out var port)) { var lst = new List <string>(args); lst.Add("error open file browser."); File.WriteAllLines("fb_error, error parse port number", lst); return(-1); } server = new IPEndPoint(localIp, port); port = NetworkEnv.GetAvailableUdpPort(); client = new UnicClient(port, (msg, ep) => { }); bool multipleSelect = bool.Parse(args[1]); string filter = args[2]; int mainCmd = int.Parse(args[3]); switch (mainCmd) { case saveFile: SaveFileDialog sf = new SaveFileDialog(); sf.Filter = filter; switch (sf.ShowDialog(ForegroundWindow.CurrentWindow)) { case DialogResult.OK: client.SendMessage(server, sf.FileName); break; case DialogResult.None: case DialogResult.Cancel: case DialogResult.Abort: case DialogResult.Retry: case DialogResult.Ignore: case DialogResult.Yes: case DialogResult.No: default: client.SendMessage(server, "cancel"); break; } break; case OpenFolder: FolderBrowserDialog fb = new FolderBrowserDialog(); fb.RootFolder = Environment.SpecialFolder.MyComputer; switch (fb.ShowDialog(ForegroundWindow.CurrentWindow)) { case DialogResult.OK: client.SendMessage(server, fb.SelectedPath); break; case DialogResult.None: case DialogResult.Cancel: case DialogResult.Abort: case DialogResult.Retry: case DialogResult.Ignore: case DialogResult.Yes: case DialogResult.No: default: client.SendMessage(server, "cancel"); break; } break; default: OpenFileDialog openfile = new OpenFileDialog(); openfile.Multiselect = multipleSelect; openfile.Filter = filter; switch (openfile.ShowDialog(ForegroundWindow.CurrentWindow)) { case DialogResult.OK: string ret = string.Empty; if (multipleSelect) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < openfile.FileNames.Length; i++) { sb.Append(openfile.FileNames[i]); if (i != openfile.FileNames.Length - 1) { sb.Append('|'); } } ret = sb.ToString(); } else { ret = openfile.FileName; } client.SendMessage(server, ret); break; case DialogResult.None: case DialogResult.Cancel: case DialogResult.Abort: case DialogResult.Retry: case DialogResult.Ignore: case DialogResult.Yes: case DialogResult.No: default: client.SendMessage(server, "cancel"); break; } break; } client.SendMessage(server, "browserExit"); return(0); }