private void Listen() { UdpSession session = null; try { IPEndPoint clientAddr = new IPEndPoint(IPAddress.Any, port); var bytes = conn.Receive(ref clientAddr); var tempSession = new UdpSession(conn, clientAddr, this); session = tempSession; if (!sessions.ContainsKey(tempSession)) { if (this.OnConn != null) { this.OnConn(session); } sessions.Add(tempSession, tempSession); } else { session = sessions[tempSession]; } if (this.OnMessage != null) { this.OnMessage(session, bytes); } } catch (Exception e) { Disconnected(session, e); } }
public void Disconnected(UdpSession session, Exception e) { this.OnError(session, e); sessions.Remove(session); }
public override bool Equals(object obj) { UdpSession session = (UdpSession)obj; return(endPoint.Equals(session.endPoint)); }