类模块之四:MsgSrv.cls----本模块中定义了消息服务器类MsgServer,该类是消息广播引擎的主体,它主要管理维护消息接收器列表(Clients),将发送来的消息(调用SendMsg过程)依次发送给列表中的所有接收器。注意,这个类被声明为公共全局类,这主要是为了方便使用(不必在每个程序中再建立该类,过程名全局有效)。
Option Explicit
/说 明:
/消 息 服 务 器 类
/发 送 消 息
Public Sub SendMsg(msg As VbMsg)
Dim c As MsgClient
For Each c In Clients
c.SetMsg msg
DoEvents
Next c
End Sub
/增 删 消 息 接 收 客 户
Public Sub AddMsgClient(c As MsgClient)
CliCount = CliCount + 1
c.Id = CliCount
Clients.Add c, c.Key
End Sub
Public Sub DelMsgClient(c As MsgClient)
Clients.Remove c.Key
If Clients.Count = 0 Then CliCount = 0
End Sub
责任编辑:虫虫