Example #1
0
        public void Startup()
        {
            try
            {
                /*
                 *  None, do as normal.
                 */

                /*
                 *  Client, try establish connection to the master FP on the network every two seconds. After connection listen to data from master and add that to the arraysToProcess queue.
                 */

                /*
                 *  Master, start listening TCP socket, for every client contacting via TCP add them as clients and send raw DCS-BIOS data to them
                 */
                Shutdown();
                if (_started)
                {
                    return;
                }
                _shutdown          = false;
                _dcsProtocolParser = DCSBIOSProtocolParser.GetParser();
                _dcsProtocolParser.Attach(_iDcsBiosDataListener);

                _ipEndPointReceiverUdp = new IPEndPoint(IPAddress.Any, ReceivePort);
                _ipEndPointSenderUdp   = new IPEndPoint(IPAddress.Parse(SendToIp), SendPort);

                _udpReceiveClient = new UdpClient();
                _udpReceiveClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                _udpReceiveClient.Client.Bind(_ipEndPointReceiverUdp);
                _udpReceiveClient.JoinMulticastGroup(IPAddress.Parse(ReceiveFromIp));

                _udpSendClient = new UdpClient();
                _udpSendClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                _udpSendClient.EnableBroadcast = true;

                _dcsbiosListeningThread = new Thread(ReceiveDataUdp);
                _dcsbiosListeningThread.Start();
                _dcsProtocolParser.Startup();

                _started = true;
            }
            catch (Exception e)
            {
                SetLastException(e);
                Common.LogError(e, "DCSBIOS.Startup()");
                if (_udpReceiveClient != null && _udpReceiveClient.Client.Connected)
                {
                    _udpReceiveClient.Close();
                    _udpReceiveClient = null;
                }
                if (_udpSendClient != null && _udpSendClient.Client != null && _udpSendClient.Client.Connected)
                {
                    _udpSendClient.Close();
                    _udpSendClient = null;
                }
            }
        }
Example #2
0
        public void Startup()
        {
            try
            {
                /*
                 *  None, do as normal.
                 */

                /*
                 *  Client, try establish connection to the master FP on the network every two seconds. After connection listen to data from master and add that to the arraysToProcess queue.
                 */

                /*
                 *  Master, start listening TCP socket, for every client contacting via TCP add them as clients and send raw DCS-BIOS data to them
                 */
                if (_isRunning)
                {
                    return;
                }
                _dcsbiosListeningThread = new Thread(ReceiveDataUdp);
                _dcsbiosListeningThread.Start();
                _dcsProtocolParser.Startup();

                _isRunning = true;
            }
            catch (Exception e)
            {
                SetLastException(e);
                Common.LogError(e, "DCSBIOS.Startup()");
                if (_udpReceiveClient != null && _udpReceiveClient.Client.Connected)
                {
                    _udpReceiveClient.Close();
                    _udpReceiveClient = null;
                }
                if (_udpSendClient != null && _udpSendClient.Client != null && _udpSendClient.Client.Connected)
                {
                    _udpSendClient.Close();
                    _udpSendClient = null;
                }
            }
        }