Ejemplo n.º 1
0
        public void socketWrite(IPEndPoint ipEndPoint, string addr)
        {
            TcpClient     sender        = null;
            NetworkStream networkStream = null;

            System.IO.StreamWriter streamWriter = null;
            try
            {
                if (socketMap.ContainsKey(ipEndPoint))
                {
                    sender        = socketMap[ipEndPoint];
                    networkStream = sender.GetStream();
                    streamWriter  = new System.IO.StreamWriter(networkStream);
                }

                StremEntity entity = null;

                while (true)
                {
                    lock (thisLock)
                    {
                        if (messageQueue.Count > 0)
                        {
                            entity = messageQueue.Dequeue();
                            if (entity != null)
                            {
                                if (sender != null)
                                {
                                    if (messageQueue.Count >= 0)
                                    {
                                        streamWriter.WriteLine(entity.toString());
                                        streamWriter.Flush();
                                        logger.Info(string.Format("send  topic : {0}  message : {1}", entity.topic, entity.content));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error(string.Format("TCP SOCKET ERROR : {0}", e.ToString()));
            }
            finally
            {
                if (streamWriter != null)
                {
                    streamWriter.Close();
                }
                if (networkStream != null)
                {
                    networkStream.Close();
                }
                if (sender != null)
                {
                    sender.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public void fileRead(string topic, string fileName)
        {
            string line;

            //파일 스트림 객체 생성
            System.IO.StreamReader file = new System.IO.StreamReader(@fileName);
            while ((line = file.ReadLine()) != null)
            {
                lock (thisLock)
                {
                    StremEntity entity = new StremEntity(topic, line);
                    messageQueue.Enqueue(entity);
                    logger.Info(string.Format("topic : {0}  message : {1} queueCnt : {2} ", topic, line, messageQueue.Count));
                    if (line == null)
                    {
                        break;
                    }
                }
            }
            file.Close();
        }