Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public void Disconnected(UdpSession session, Exception e)
        {
            this.OnError(session, e);

            sessions.Remove(session);
        }
Ejemplo n.º 3
0
        public override bool Equals(object obj)
        {
            UdpSession session = (UdpSession)obj;

            return(endPoint.Equals(session.endPoint));
        }