public void Shutdown() { try { try { _shutdown = true; DBCommon.DebugP("DCSBIOS is SHUTTING DOWN"); _dcsProtocolParser.Shutdown(); _dcsbiosListeningThread?.Abort(); } catch (Exception) { } try { _udpReceiveClient.Close(); } catch (Exception) { } try { _udpSendClient.Close(); } catch (Exception) { } /* * try * { * _tcpListener.Stop(); * } * catch (Exception) * { * } * try * { * _tcpClient.Close(); * } * catch (Exception) * { * } */ _started = false; } catch (Exception ex) { SetLastException(ex); DBCommon.LogError(9212, ex, "DCSBIOS.Shutdown()"); } }
public void Shutdown() { try { _udpReceiveClient?.Close(); _udpReceiveClient?.Close(); _dcsProtocolParser?.Detach(_iDcsBiosDataListener); _dcsProtocolParser?.Shutdown(); _udpReceiveClient = null; _udpReceiveClient = null; _dcsProtocolParser = null; _isRunning = false; } catch (Exception ex) { SetLastException(ex); Common.LogError(ex, "DCSBIOS.Shutdown()"); } }
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; Common.DebugP("DCSBIOS is STARTING UP"); _dcsProtocolParser?.Detach(_iDcsBiosDataListener); _dcsProtocolParser?.Shutdown(); _dcsProtocolParser = DCSBIOSProtocolParser.GetParser(); _dcsProtocolParser.Attach(_iDcsBiosDataListener); _ipEndPointReceiverUdp = new IPEndPoint(IPAddress.Any, ReceivePort); _ipEndPointSenderUdp = new IPEndPoint(IPAddress.Parse(SendToIp), SendPort); _udpReceiveClient?.Close(); _udpReceiveClient = new UdpClient(); _udpReceiveClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); _udpReceiveClient.Client.Bind(_ipEndPointReceiverUdp); _udpReceiveClient.JoinMulticastGroup(IPAddress.Parse(ReceiveFromIp)); _udpSendClient?.Close(); _udpSendClient = new UdpClient(); _udpSendClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); _udpSendClient.EnableBroadcast = true; _dcsbiosListeningThread?.Abort(); _dcsbiosListeningThread = new Thread(ReceiveDataUdp); _dcsbiosListeningThread.Start(); _dcsProtocolParser.Startup(); _started = true; } catch (Exception e) { SetLastException(e); Common.LogError(9211, 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; } } }