Example #1
0
        public void StartThreads()
        {
            IPAddress[] ipAddresses = ConnectionServer.GetValidLocalAddress();
            if (ipAddresses == null)
            {
                m_Log.Log(" no local IP addresses found, exiting", ErrorLog.LOG_TYPE.FATAL);
                return;
            }

            bool loopBackAddressFound = false;


            foreach (IPAddress addr in ipAddresses)
            {
                try
                {
                    // eliminate duplicates
                    if (!m_LocalHostPortsTable.Contains(addr.ToString()))
                    {
                        if (addr.ToString().Contains("127.0"))
                        {
                            loopBackAddressFound = true;
                        }

                        m_LocalHostPortsTable.Add(addr.ToString(), addr.ToString());

                        m_Log.Log("IP Server listening on host addr: " + addr.ToString(), ErrorLog.LOG_TYPE.INFORMATIONAL);

                        ConnectionServer con = new ConnectionServer(addr, 13000, HandleReceivedMessage, m_AppData);
                        m_Server.Add(con);
                    }
                }
                catch (Exception ex) { m_Log.Trace(ex, ErrorLog.LOG_TYPE.FATAL); }
            }

            // ensure we are listening to the loop back 127.0.0.1
            if (!loopBackAddressFound)
            {
                try
                {
                    ConnectionServer con = new ConnectionServer(IPAddress.Loopback, 13000, HandleReceivedMessage, m_AppData);
                    m_Server.Add(con);
                }
                catch (Exception ex) { m_Log.Trace(ex, ErrorLog.LOG_TYPE.FATAL); }
            }
        }
        public void StartThreads()
        {
            IPAddress[] ipAddresses = ConnectionServer.GetValidLocalAddress();
            if (ipAddresses == null)
            {
                m_Log.Log(" no local IP addresses found, exiting", ErrorLog.LOG_TYPE.FATAL);
                return;
            }

            bool loopBackAddressFound = false;

            foreach (IPAddress addr in ipAddresses)
            {
                try
                {
                    // eliminate duplicates
                    if (!m_LocalHostPortsTable.Contains(addr.ToString()))
                    {
                        if (addr.ToString().Contains("127.0")) loopBackAddressFound = true;

                        m_LocalHostPortsTable.Add(addr.ToString(), addr.ToString());

                        m_Log.Log("IP Server listening on host addr: " + addr.ToString(), ErrorLog.LOG_TYPE.INFORMATIONAL);

                        ConnectionServer con = new ConnectionServer(addr, 13000, HandleReceivedMessage, m_AppData);
                        m_Server.Add(con);
                    }
                }
                catch (Exception ex) { m_Log.Trace(ex, ErrorLog.LOG_TYPE.FATAL); }

            }

            // ensure we are listening to the loop back 127.0.0.1
            if (!loopBackAddressFound)
            {
                try
                {
                    ConnectionServer con = new ConnectionServer(IPAddress.Loopback, 13000, HandleReceivedMessage, m_AppData);
                    m_Server.Add(con);
                }
                catch (Exception ex) { m_Log.Trace(ex, ErrorLog.LOG_TYPE.FATAL); }

            }
        }
        void HandleReceivedMessage(RCS_Protocol.RCS_Protocol.PACKET_TYPES type, byte[] data, ConnectionServer.ClientConnection connection, object packetHeader)
        {
            try
            {
                switch (type)
                {
                    case RCS_Protocol.RCS_Protocol.PACKET_TYPES.REQUEST_STATS:
                        {
                            // CreatePacket(PACKET_TYPES type, string data)
                            connection.SendHealthStats(m_AppData.HealthStatistics);

                        }
                        break;
                    case RCS_Protocol.RCS_Protocol.PACKET_TYPES.REQUEST_CHANNEL_LIST:
                        {
                            FrameGenerator fg = (FrameGenerator)m_AppData.FrameGenerator;
                            string[] list = fg.GetChannelList();
                            connection.SendChannelList(list);
                        }
                        break;

                    case RCS_Protocol.RCS_Protocol.PACKET_TYPES.REQUEST_LIVE_VIEW:
                        {
                            RCS_Protocol.RCS_Protocol.LIVE_VIEW_HEADER jpegHeader = (RCS_Protocol.RCS_Protocol.LIVE_VIEW_HEADER)packetHeader;

                            // parse out the requested channel ID from the info string

                            // int channel = Convert.ToInt32(jpegHeader.cameraName);
                            string timeStamp = null;
                            int channelIndex = 0;
                            string lastPlateReading = null;
                            byte[] jpeg = GetCurrentJpeg(jpegHeader.cameraName, out timeStamp, out lastPlateReading, out channelIndex);
                            if (jpeg == null)
                            {
                                jpeg = new byte[10]; // will be treated as null image on receiving end, but keep the state machine going
                            }
                            connection.SendJpeg(jpeg, jpegHeader.cameraName, timeStamp, lastPlateReading);
                            jpeg = null;
                        }
                        break;

                    case RCS_Protocol.RCS_Protocol.PACKET_TYPES.REQUEST_HOST_NAME:
                        {
                            connection.SendHostName(m_AppData.ThisComputerName);
                        }
                        break;
                }
            }
            catch (Exception ex) { m_Log.Trace(ex, ErrorLog.LOG_TYPE.FATAL); }
        }