/// <summary> /// 关闭通道服务 /// </summary> public void StopService() { if (this._listener != null) { this._listener.Stop(); this._listener = null; } //foreach (IDataChannel dc in this._channelList) // dc.Close(); }
public string StartService() { if (this._listener != null) { return("服务已启动"); //防止重复启动侦听 } //参数ip 和port 将来从配置文件中读取。 _listener = new MeterTCPChannelLister(ip, port); _listener.OnReceviceConnected += new ConnectionMessageHandle(OnReceviceConnected); //_listener.OnConnectClosed += _listener_OnConnectClosed; _listener.OnTcpListenerStoped += new EventHandler(OnTcpListenerStoped); this._listenThread = new Thread(new ThreadStart(Start)); this._listenThread.Start(); //添加日志 Log.getInstance().Write(MsgType.Information, "物联网表后台服务启动成功,服务器IP:" + this.ip + " 端口号:" + this.port.ToString()); return("物联网表后台服务启动成功,服务器IP:" + this.ip + " 端口号:" + this.port.ToString()); }