110,021
社区成员




//事件委托
public delegate void SocketEvent(MsgSocket ms);
//接收到消息事件
public event SocketEvent msg_received;
//客户端离线事件
public event SocketEvent disconnection_event;
//增加侦听的方法
public void addEventListener(String type, SocketEvent se)
{
switch (type)
{
case MsgEvent.MSG_RECEIVED:
this.msg_received += new SocketEvent(se);
//这边添加侦听成功,所以可以接收到其他对象发送的消息。
break;
case MsgEvent.DISCONNECTION:
this.disconnection_event += new SocketEvent(se);
break;
default:
break;
}
}
//移除侦听的方法
public void removeEventListener(String type, SocketEvent se)
{
switch (type)
{
case MsgEvent.MSG_RECEIVED:
this.msg_received -= new SocketEvent(se);
//这句确实被执行了,但是就是不移除侦听,仍然在接收其他对象,但是连接已经关闭,发生错误。
break;
case MsgEvent.DISCONNECTION:
this.disconnection_event -= new SocketEvent(se);
break;
default:
break;
}
}