public Server(string[] argv) { int argc = 0; while (argc < argv.Length) { if (argc + 1 < argv.Length && argv[argc] == "-sharepath") { _share = argv[++argc]; } else if (argc + 1 < argv.Length && argv[argc] == "-serialport") { _tty = argv[++argc]; } else if (argc + 1 < argv.Length && argv[argc] == "-vooplayer") { _vooplayerappbundlepath = argv[++argc]; } else if (argc + 1 < argv.Length && argv[argc] == "-listenport") { _port = Convert.ToInt32(argv[++argc]); } else { Usage(true); } argc++; } try { if (_tty != "") { SerialPort sp = new SerialPort(_tty, 115200, Parity.None, 8, StopBits.One); sp.Open(); _comms = new CommsProcessor(new CommsInterface(sp)); _comms.SourceSelectionReceived += delegate(int src) { Client.Broadcast("*comms source " + src); }; _comms.VolumeReceived += delegate(int vol) { Client.Broadcast("*comms volume " + vol); }; _comms.OffReceived += delegate() { Client.Broadcast("*comms off"); }; } } catch { } TcpListener tcpListener = new TcpListener(IPAddress.Any, _port); (new Thread(delegate() { tcpListener.Start(); while (true) { try { Client c = new Client(this, tcpListener.AcceptTcpClient(), _share); lock (_lock) { c.Send("*" + _state); c.Send("*" + _seekable); c.Send("*" + _subtitle); c.Send("*" + _subtitlecount); c.Send("*" + _audiotrack); c.Send("*" + _audiotrackcount); c.Send("*" + _time); if (_comms != null) { c.Send("*comms volume " + _comms.SystemVolume); if (_comms.IsOff) { c.Send("*comms off"); } else { c.Send("*comms source " + _comms.SystemSourceNum); } } } } catch (Exception e) { Console.WriteLine("error creating client: " + e.ToString()); } } }) { IsBackground = true }).Start(); }
public Server(string[] argv) { int argc = 0; while (argc < argv.Length) { if (argc+1 < argv.Length && argv[argc] == "-sharepath") { _share = argv[++argc]; } else if (argc+1 < argv.Length && argv[argc] == "-serialport") { _tty = argv[++argc]; } else if (argc+1 < argv.Length && argv[argc] == "-vooplayer") { _vooplayerappbundlepath = argv[++argc]; } else if (argc+1 < argv.Length && argv[argc] == "-listenport") { _port = Convert.ToInt32(argv[++argc]); } else { Usage(true); } argc++; } try { if (_tty != "") { SerialPort sp = new SerialPort(_tty, 115200, Parity.None, 8, StopBits.One); sp.Open(); _comms = new CommsProcessor(new CommsInterface(sp)); _comms.SourceSelectionReceived += delegate(int src) { Client.Broadcast("*comms source " + src); }; _comms.VolumeReceived += delegate(int vol) { Client.Broadcast("*comms volume " + vol); }; _comms.OffReceived += delegate() { Client.Broadcast("*comms off"); }; } } catch { } TcpListener tcpListener = new TcpListener(IPAddress.Any, _port); (new Thread(delegate() { tcpListener.Start(); while (true) { try { Client c = new Client(this, tcpListener.AcceptTcpClient(), _share); lock (_lock) { c.Send("*" + _state); c.Send("*" + _seekable); c.Send("*" + _subtitle); c.Send("*" + _subtitlecount); c.Send("*" + _audiotrack); c.Send("*" + _audiotrackcount); c.Send("*" + _time); if (_comms != null) { c.Send("*comms volume " + _comms.SystemVolume); if (_comms.IsOff) c.Send("*comms off"); else c.Send("*comms source " + _comms.SystemSourceNum); } } } catch (Exception e) { Console.WriteLine("error creating client: " + e.ToString()); } } }) { IsBackground = true }).Start(); }