示例#1
0
 private void StartUDPListener()
 {
     if (UDPListener == null)
     {
         UDPListener = new UDPListener();
         UDPListener.DeviceNotificationRecieved += HandleUDP;
         UDPListener.StartListener(Musiccast.Model.Constants.UDP_ListenPort);
     }
 }
示例#2
0
 static void StartSyslogServer()
 {
     #region SimpleInjector
     var container = new SimpleInjector.Container();
     container.Register <IMessageParser, MessageParser>();
     container.Register <IMessageStorage>(() => new MemoryStorage(10000));
     container.Verify();
     #endregion
     UDPListener listener = new UDPListener(8888);
     listener.StartListener(container.GetInstance <IMessageStorage>(), container.GetInstance <IMessageParser>());
 }
 private static void StartListener()
 {
     Console.Clear();
     CreateDB(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StrangeGt.ForzaMotorsport", "databases", string.Format("Forzamotorsport_{0:yyyyMMddHHmmss}.sqlite", DateTime.Now.ToUniversalTime())));
     if (listener == null)
     {
         listener            = new UDPListener();
         listener.OnReceive += Listener_OnReceive;
     }
     listener.StartListener();
 }
示例#4
0
        static void Main(string[] args)
        {
            if (args[0] == "sender")
            {
                Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                IPAddress broadcast = IPAddress.Parse("192.168.100.5");

                byte[]     sendbuf = Encoding.UTF8.GetBytes("Hola Mundo");
                IPEndPoint ep      = new IPEndPoint(broadcast, 11000);

                s.SendTo(sendbuf, ep);

                Console.WriteLine("Message sent to the broadcast address");
            }
            else
            {
                UDPListener udpl = new UDPListener();
                udpl.StartListener();
            }
        }
 public ItemDetailViewModel()
 {
     Title         = "UDPData";
     StartListener = new Command((object arg) =>
     {
         if (listener == null)
         {
             listener            = new UDPListener();
             listener.OnReceive += Listener_OnReceive;
             listener.OnStart   += Listener_OnStart;
             listener.OnStop    += Listener_OnStop;
         }
         listener.StartListener();
     }, CanExecuteStartListener);
     StopListener = new Command((object arg) =>
     {
         if (listener != null)
         {
             listener.StopListener();
         }
     }, CanExecuteStopListener);
 }
示例#6
0
        public FMain()
        {
#if DEBUG
            TextWriterTraceListener[] listeners = new TextWriterTraceListener[] {
                new TextWriterTraceListener("debug." + Guid.NewGuid() + ".log"),
                new TextWriterTraceListener(Console.Out)
            };
            foreach (TextWriterTraceListener listener in listeners)
            {
                listener.TraceOutputOptions |= TraceOptions.DateTime;
            }
            Trace.Listeners.AddRange(listeners);
            Trace.AutoFlush = true;
            Trace.TraceInformation("-----------------------START---------------------------------");
#endif
            config = new XmlConfigNS.XmlConfig <DXpConfig>();
            config.data.initialize();
            qsoFactory = new QSOFactory(config.data);
            InitializeComponent();
            udpListener.DataReceived += UDPDataReceived;
            udpListener.StartListener(12060);

            bsQSO = new BindingSource(blQSO, null);
            dgvQSO.AutoGenerateColumns = false;
            dgvQSO.DataSource          = bsQSO;
            for (int c = 0; c < DXpConfig.UserColumnsCount; c++)
            {
                UserColumnSettings cs  = config.data.userColumns != null && config.data.userColumns.Count > c ? config.data.userColumns[c] : null;
                DataGridViewColumn col = new DataGridViewTextBoxColumn();
                col.Name             = "userFieldColumn" + c.ToString();
                col.DataPropertyName = "userField" + c.ToString();
                col.Visible          = cs != null ? cs.show : false;
                col.HeaderText       = cs != null ? cs.name : "";
                dgvQSO.Columns.Add(col);
            }
            if (config.data.dgvQSOColumnsWidth != null)
            {
                for (int co = 0; co < dgvQSO.ColumnCount && co < config.data.dgvQSOColumnsWidth.Count(); co++)
                {
                    dgvQSO.Columns[co].Width = config.data.dgvQSOColumnsWidth[co];
                }
            }
            else
            {
                config.data.dgvQSOColumnsWidth = new List <int>();
            }
            if (config.data.dgvQSOColumnsWidth.Count < dgvQSO.ColumnCount)
            {
                for (int co = config.data.dgvQSOColumnsWidth.Count; co < dgvQSO.ColumnCount; co++)
                {
                    config.data.dgvQSOColumnsWidth.Add(dgvQSO.Columns[co].Width);
                }
                writeConfig();
            }

            bool       qsoEr;
            List <QSO> storedQSOs = ProtoBufSerialization.ReadListItems <QSO>(qsoFilePath, out qsoEr);
            if (storedQSOs.Count > 0)
            {
                Regex  reComaNoSpace   = new Regex(",(\\S)");
                string comaNoSpaceRepl = ", $1";
                Regex  reNoRegion      = new Regex("(\\w\\w)-(\\d\\d),\\s?(\\d\\d)");
                string noRegionRepl    = "$1-$2, $1-$3";
                Regex  reRDA           = new Regex("[A-Z][A-Z]-\\d\\d");
                foreach (QSO qso in storedQSOs)
                {
                    if (qso.freq.IndexOf('.') == -1)
                    {
                        qso.freq = QSO.formatFreq(qso.freq);
                        qsoEr    = true;
                    }
                    if (qso.rda != null)
                    {
                        MatchCollection rdaMatches = reRDA.Matches(qso.rda);
                        string          rda        = "";
                        if (rdaMatches.Count > 1)
                        {
                            qsoEr = true;
                        }
                        foreach (Match rdaMatch in rdaMatches)
                        {
                            if (rda != "")
                            {
                                rda += ", ";
                            }
                            rda += rdaMatch.Value;
                        }
                        qso.rda = rda;
                    }

                    /*
                     * if (qso.rda != null && reComaNoSpace.IsMatch(qso.rda))
                     * {
                     *  qso.rda = reComaNoSpace.Replace(qso.rda, comaNoSpaceRepl);
                     *  qsoEr = true;
                     * }
                     * if (qso.rda != null && reNoRegion.IsMatch(qso.rda))
                     * {
                     *  qso.rda = reNoRegion.Replace(qso.rda, noRegionRepl);
                     *  qsoEr = true;
                     * }*/
                    blQSO.Insert(0, qso);
                    updateQsoIndex(qso);
                }
                QSO lastQSO = storedQSOs.Last();
                if (lastQSO.rda == config.data.getOptionalColumnValue("RDA"))
                {
                    qsoFactory.no = lastQSO.no + 1;
                }
            }
            if (qsoEr)
            {
                ProtoBufSerialization.WriteList(qsoFilePath, storedQSOs, false);
            }
            config.data.optionalColumnValueChanged += optionalColumnValueChanged;
            gpsReader.locationChanged      += locationChanged;
            gpsReader.gpsConnectionChanged += gpsConnectionChanged;
            config.data.logIO += onLoggedIO;
            onLoggedIO(null, null);
            startGPSReader();
            http = new HTTPService(gpsReader, config.data);
            http.connectionStateChanged += onHTTPConnection;
            http.locationChanged        += locationChanged;
        }