Example #1
0
 public SocketPort(object obj)
 {
     if (obj is ICommand)
     {
         mDispatcher = obj as ICommand;
     }
     else if (obj is SocketCmdOperator)
     {
         mSocketCmdOperator = obj as SocketCmdOperator;
     }
     else
     {
         throw new ArgumentException("argument is not the type expected:",obj.GetType().Name);
     }
 }
Example #2
0
        public Service1()
        {
            InitializeComponent();

            string fullPath = System.IO.Path.GetDirectoryName(typeof(Service1).Assembly.Location);
            mLogFileStream = new FileStream(fullPath +"\\"+ typeof(Service1).Name + ".log", FileMode.Create);
            TextWriterTraceListener listener = new System.Diagnostics.TextWriterTraceListener(mLogFileStream);
            Trace.Listeners.Clear();
            Trace.Listeners.Add(listener);
            Trace.AutoFlush = true;

            //change current directory to local directory instead of system32
            System.IO.Directory.SetCurrentDirectory(fullPath);

            /*******************************Initialize service task*************************************************/

            //Add networkMonitor task
            //var nICTask = NICTaskFactory.Instance.GetTask();
            //NICTaskFactory.Instance.InsertNetworkUtilization(nICTask);
            //TaskExcuteProcess.Instance.Add(nICTask);

            //Add communicaiton task
            Command command = new Command();
            command.CommandReceived += new CommandInterpretion.BTCommandInterpreter().CommandEventHandler;
            command.CommandReceived += new CommandInterpretion.WIFICommandInterpreter().CommandEventHandler;

            SocketCmdOperator socketCmdOperator = new SocketCmdOperator();

            var communicationTask = CommunicationTaskFactory.Instance.GetTask();
            //CommunicationTaskFactory.Instance.InsertMessagePort(communicationTask,typeof(NetworkInterfaceInfo));
            CommunicationTaskFactory.Instance.InsertMessagePort(communicationTask, command);
            //CommunicationTaskFactory.Instance.InsertSocketPort(communicationTask, command);
            CommunicationTaskFactory.Instance.InsertSocketPort(communicationTask, socketCmdOperator);
            CommunicationTaskFactory.Instance.InsertMessagePort(communicationTask,typeof(BusinessWork.Service));
            TaskExcuteProcess.Instance.Add(communicationTask);
        }
Example #3
0
        public void DealData()
        {
            IPEndPoint clientip = (IPEndPoint)_client.RemoteEndPoint;
            Console.WriteLine("connect with client:" + clientip.Address + " at port:" + clientip.Port);

            try
            {
                while (true)
                {
                    _receiveCount = _client.Receive(_receiveBytes);
                    Console.WriteLine("recv=" + _receiveCount.ToString());
                    if (_receiveCount == 0)//当信息长度为0,说明客户端连接断开
                        break;
                    _socketCmdOperator = new SocketCmdOperator();
                    byte[] result = _socketCmdOperator.Do(_receiveBytes, _receiveCount);
                    _client.Send(result, result.Length, SocketFlags.None);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.WriteLine("Disconnected from" + clientip.Address);
            _client.Close();
        }