我们正在为当前登录的用户异步创建一个新的套接字。服务器将在适当的时候通知这个用户,然后可能会在不同的视图页面中的用户出现一个弹出消息。我们正在创建像这样的套接字:
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.BeginReceive(buffer, 0, buffer.Length, 0,
new AsyncCallback(ReceiveNotification), socket);
private void ReceiveNotification(IAsyncResult ar)
{
Socket socket = (Socket)ar.AsyncState;
socket.EndReceive(ar);
//Need to perform notification stuff here
socket.Close();
}