HTML and CSS Reference
In-Depth Information
if (agent != null)
{
WsClientConnection client =
new WsClientConnection(sender, agent, clientID, name);
// Re-wire the event handlers
sender.Disconnected -= Disconnected;
sender.MessageReceived -= MessageReceived;
sender.Disconnected += client.Disconnected;
sender.MessageReceived += client.MessageReceived;
client.ClientDisconnected+=
new WsDisconnectedClientEventHandler(ClientDisconnected);
// Add this to the agent list
_unknown.Remove(sender);
_clients.Add(client);
agent._clients[clientID]=client;
// Send a message to the agent
agent.SendMessage("[ClientName:"+clientID.ToString() +
name+"]");
// Send a response
client.SendMessage("Hello! My name is "+agent._name +
". How may I help you?");
}
else
{
// There are no agents available
sender.SendMessage("There are no agents currently available;" +
"please try again later");
}
}
}
As I explained earlier, the first message that is sent by both the client and agent applications is a sign-on
message that includes their name. This will be formatted like one of these. Any other message will be ignored.
Agent = “[Agent SignOn:<agent name>]”
Client = “[Client SignOn:<client name>]”
The MessageReceived() event handler checks to see if the incoming message is one of these. For an
agent sign-on, the name is extracted from the message. It then creates a WsAgentConnection class and sets its
_name property. The MessageReceived and Disconnected events from the WsConnection object are currently
mapped to the WsServer event handler. This mapping is removed and instead, these events are mapped to the
WsAgentConnection object's event handers. Also, the WsAgentConnection class defines an AgentDisconnected
event, which is mapped to a new event handler that you will implement later. The WsConnection object is
removed from the _unknown list and the WsAgentConnection object is added to the _agents list. Finally, a
welcome message is sent to the agent application.
 
Search WWH ::




Custom Search