/// <summary> /// FD event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void scp_ReceivedEvent(object sender, EventArgs e) { SocketCommuniPort sckcp = sender as SocketCommuniPort; byte[] bs = sckcp.Read(); this.CommuniSoft.FDManager.Process(sckcp, bs); }
/// <summary> /// /// </summary> private void UnreginsterEvents(CommuniPort cp) { SocketCommuniPort sckcp = cp as SocketCommuniPort; sckcp.ClosedEvent -= new EventHandler(sckcp_ClosedEvent); sckcp.ReceivedEvent -= new EventHandler(sckcp_ReceivedEvent); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void item_ConnectedEvent(object sender, EventArgs e) { SocketListener sl = sender as SocketListener; Socket newsocket = sl.NewSocket; if (newsocket == null) { return; } if (!newsocket.Connected) { return; } SocketCommuniPort scp = null; try { scp = new SocketCommuniPort(newsocket); } catch { CloseSocket(newsocket); return; } scp.ReceivedEvent += new EventHandler(scp_ReceivedEvent); bool b = StationCommuniPortBinder.Bind( this._communiSoft.HardwareManager.Stations, scp); if (!b) { this._communiSoft.CommuniPortManager.Add(scp); } }
/// <summary> /// /// </summary> /// <returns></returns> public SocketCommuniPort CreateSocketCommuniPort(Socket socket ) { if (socket == null) throw new ArgumentNullException("socket"); SocketCommuniPort scp = new SocketCommuniPort(socket); return scp; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sckcp_ReceivedEvent(object sender, EventArgs e) { SocketCommuniPort sckcp = sender as SocketCommuniPort; byte[] bytes = sckcp.Read(); CommuniPortReceivedEventArgs e2 = new CommuniPortReceivedEventArgs(sckcp, bytes); OnCommuniPortReceived(e2); }
/// <summary> /// /// </summary> private void RegisterEvents(CommuniPort cp) { SocketCommuniPort sckcp = cp as SocketCommuniPort; if (sckcp != null) { sckcp.ClosedEvent += new EventHandler(sckcp_ClosedEvent); sckcp.ReceivedEvent += new EventHandler(sckcp_ReceivedEvent); } }
/// <summary> /// /// </summary> /// <returns></returns> public SocketCommuniPort CreateSocketCommuniPort(Socket socket) { if (socket == null) { throw new ArgumentNullException("socket"); } SocketCommuniPort scp = new SocketCommuniPort(socket); return(scp); }
/// <summary> /// /// </summary> /// <param name="stations"></param> /// <param name="scp"></param> internal static bool Bind(StationCollection stations, SocketCommuniPort scp) { foreach (Station st in stations) { if (scp.Match(st.CommuniType)) { ClearBind(st); return(Bind(st, scp)); } } return(false); }
/// <summary> /// /// </summary> /// <param name="stations"></param> /// <param name="scp"></param> internal static bool Bind(StationCollection stations, SocketCommuniPort scp) { foreach (Station st in stations) { if (scp.Match(st.CommuniType)) { ClearBind(st); return Bind(st, scp); } } return false; }
/// <summary> /// 删除集合中已经存在的,相同远程地址的SocketCommuniPort /// </summary> /// <param name="cp"></param> private void BeforeAdd(CommuniPort cp) { // TODO: allow same ip address option // if (cp is SocketCommuniPort) { SocketCommuniPort scp = cp as SocketCommuniPort; for (int i = this.CommuniPorts.Count - 1; i >= 0; i--) { CommuniPort cp2 = this.CommuniPorts[i]; if (cp2 is SocketCommuniPort) { SocketCommuniPort scp2 = cp2 as SocketCommuniPort; IPEndPoint ipep = scp.RemoteEndPoint as IPEndPoint; IPEndPoint ipep2 = scp2.RemoteEndPoint as IPEndPoint; if (ipep.Address.Equals(ipep2.Address)) { Remove(cp2); } } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void item_ConnectedEvent(object sender, EventArgs e) { SocketListener sl = sender as SocketListener; Socket newsocket = sl.NewSocket; if( newsocket == null) return; if (!newsocket.Connected) { return; } SocketCommuniPort scp = null; try { scp = new SocketCommuniPort(newsocket); } catch { CloseSocket(newsocket); return; } scp.ReceivedEvent += new EventHandler(scp_ReceivedEvent); bool b = StationCommuniPortBinder.Bind( this._communiSoft.HardwareManager.Stations, scp); if (!b) { this._communiSoft.CommuniPortManager.Add(scp); } }
/// <summary> /// /// </summary> /// <param name="socketCP"></param> public SocketCommuniPortConnectedState(SocketCommuniPort socketCP) : base(socketCP) { }