HTML and CSS Reference
In-Depth Information
However, once the specialized class is created ( WsAgentConnection or WsClientConnection ), this class will need
to handle these events. To do this, the WsServer object must remove the event handlers, and then associate the
event handlers from the new class. The specialized classes will both re-raise the Disconnected event which the
WsServer object will handle.
eXerCISe 13-4. eNhaNCING the WeBSOCKet SerVer
1. In the Solution Explorer, right-click the WsServer project and select the Add ➤ Class
links. Enter WsAgentConnection.cs for the class name.
2. Enter the code shown in Listing 13-8 as the implementation for this class.
Listing 13-8. Implementing the WsAgentConnection class
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
namespace WsServer
public delegate void WsDisconnectedAgentEventHandler
(WsAgentConnection sender, EventArgs e);
public class WsAgentConnection : IDisposable
private WsConnection _connection;
public string _name;
public Dictionary<int, WsClientConnection>_clients;
public event WsDisconnectedAgentEventHandler AgentDisconnected;
public WsAgentConnection(WsConnection conn, string name)
// Initialize our client list
_clients=new Dictionary<int, WsClientConnection>();
for (int i=1; i<= 4; i++)
_clients.Add(i, null);
public void MessageReceived(WsConnection sender,
MessageReceivedEventArgs e)
Search WWH ::

Custom Search