Exemplo n.º 1
0
        public void sendmessage(StremEntity entity)
        {
            if (entity != null)
            {
                if (entity.header.Equals("0022"))
                {
                    STRUCT_0022 data = new STRUCT_0022(entity.topic, entity.content);
                    data0022 = data;
                    dataProc(data);

                    /*
                     * if (querrydata != null)
                     * {
                     *  mainForm.view2.dataProc(querrydata);
                     * }
                     */
                }
                else if (entity.header.Equals("0374"))
                {
                    STRUCT_0374 data = new STRUCT_0374(entity.topic, entity.content);
                    if (data0022 != null)
                    {
                        querrydata = dataProc_Query(data, data0022);
                        dataProc(querrydata);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void GetDataFromQueue()
        {
            STRUCT_0374_0022 querrydata = null;
            STRUCT_0022      data0022   = null;

            while (true)
            {
                while (mainForm.messageQueue.Count > 0)
                {
                    StremEntity entity = mainForm.messageQueue.Dequeue();
                    if (entity != null)
                    {
                        if (entity.header.Equals("0022"))
                        {
                            STRUCT_0022 data = new STRUCT_0022(entity.topic, entity.content);
                            data0022 = data;
                            dataProc(data);

                            /*
                             * if (querrydata != null)
                             * {
                             *  mainForm.view2.dataProc(querrydata);
                             * }
                             */
                        }
                        else if (entity.header.Equals("0374"))
                        {
                            STRUCT_0374 data = new STRUCT_0374(entity.topic, entity.content);
                            if (data0022 != null)
                            {
                                querrydata = dataProc_Query(data, data0022);
                                dataProc(querrydata);
                            }
                        }
                    }
                    // Thread.Sleep(1);
                }
            }
        }
Exemplo n.º 3
0
 public void listener(IPEndPoint endpoint, string listen_topic)
 {
     if (socketMap.ContainsKey(endpoint))
     {
         TcpListener   listener      = null;
         TcpClient     client        = null;
         NetworkStream networkStream = null;
         StreamReader  streamReader  = null;
         try
         {
             listener = socketMap[endpoint];
             listener.Start();
             while (true)
             {
                 client = listener.AcceptTcpClient();
                 logger.Info(string.Format("accept socket {0}", client.Client.RemoteEndPoint));
                 networkStream = client.GetStream();
                 streamReader  = new StreamReader(networkStream);
                 while (client.Connected)
                 {
                     /* size[4]+topic[4]+header[4] */
                     string getData = streamReader.ReadLine();
                     if (getData.Length > 0)
                     {
                         string      length  = getData.Substring(0, 4);
                         string      topic   = getData.Substring(4, 4);
                         string      header  = getData.Substring(8, 4);
                         string      content = getData.Substring(12, getData.Length - 12);
                         StremEntity entity  = new StremEntity(topic, content);
                         view1.sendmessage(entity);
                         // messageQueue.Enqueue(entity);
                         logger.Info(string.Format("receve msg {0}", getData));
                     }
                 }
             }
         }
         catch (Exception error)
         {
             logger.Error(error.ToString());
         }
         finally
         {
             if (streamReader != null)
             {
                 streamReader.Close();
             }
             if (client != null)
             {
                 client.Close();
             }
             if (networkStream != null)
             {
                 networkStream.Close();
             }
         }
     }
     else
     {
         logger.Error(string.Format("Does not exist Socket in Map {0}", endpoint));
     }
 }