/// <summary> /// 初始化 /// </summary> public override void DoInit() { try { foreach (Config.SocketSItem item in this.config.SocketSItems) { if (!item.IsActive) { continue; } Bp.Socket.Server server = new Bp.Socket.Server(item.IP, item.Port, item); server.TimeOut = item.OutTime; server.TimeHeart = item.HeartSecond; Sokcets.Add(item.SocketDevice, server); } IDictionaryEnumerator enumerator = this.Sokcets.GetEnumerator(); while (enumerator.MoveNext()) { Bp.Socket.Server socket = enumerator.Value as Bp.Socket.Server; socket.OnSocketReceive += new Bp.Socket.Server.SocketReceiveDelegate(socket_OnSocketReceive); socket.OnSocketItemChange += new Bp.Socket.Server.SocketItemChange(socket_OnSocketItemChange); socket.DoInit(); } } catch (Exception ex) { throw new InitException(this.ToString(), ex.ToString()); } }
/// <summary> /// 释放 /// </summary> public override void DoRelease() { try { IDictionaryEnumerator enumerator = this.Sokcets.GetEnumerator(); while (enumerator.MoveNext()) { Bp.Socket.Server socket = enumerator.Value as Bp.Socket.Server; socket.DoRelease(); } } catch (Exception ex) { throw new ReleaseException(this.ToString(), ex.ToString()); } }
/// <summary> /// 启动 /// </summary> public override void DoStart() { try { IDictionaryEnumerator enumerator = this.Sokcets.GetEnumerator(); while (enumerator.MoveNext()) { Bp.Socket.Server socket = enumerator.Value as Bp.Socket.Server; socket.DoStart(); ((Config.SocketSItem)socket.DeviceType).IsConnected = true; } } catch (Exception ex) { throw new StartException(this.ToString(), ex.ToString()); } }
/// <summary> /// 发送数据 /// </summary> /// <param name="device"></param> /// <param name="data"></param> public void SocketSend(Common.SocketDevice device, byte[] data) { Bp.Socket.Server socket = (Bp.Socket.Server)Sokcets[device]; socket.SendData(data); }