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 DCSBIOS(IDcsBiosDataListener iDcsBiosDataListener, string ipFromUdp, string ipToUdp, int portFromUdp, int portToUdp, DcsBiosNotificationMode dcsNoficationMode)
        {
            IPAddress ipAddress;

            _iDcsBiosDataListener = iDcsBiosDataListener;
            if (!string.IsNullOrEmpty(ipFromUdp) && IPAddress.TryParse(ipFromUdp, out ipAddress))
            {
                _dcsbiosReceiveFromIPUdp = ipFromUdp;
            }
            if (!string.IsNullOrEmpty(ipToUdp) && IPAddress.TryParse(ipToUdp, out ipAddress))
            {
                _dcsbiosSendToIPUdp = ipToUdp;
            }
            if (portFromUdp > 0)
            {
                _dcsbiosReceivePortUdp = portFromUdp;
            }
            if (portToUdp > 0)
            {
                _dcsbiosSendPortUdp = portToUdp;
            }
            _dcsBiosNotificationMode = dcsNoficationMode;

            _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;

            //_tcpIpPort = tcpIpPort;
            _dcsBIOSInstance = this;
        }