Looking for the same application but using WCF Duplex binding instead of sockets?
Check out the Silverlight Chat application with WCF Duplex Binding.
My goal was to build a silverlight chat application.
Silverlight will be my client, and I had to build a host, to host the chatroom. The host needs to be able to push messages to the clients. I am not able to push messages to silverlight using webservices, so therefore I used sockets to push data to the silverlight client.
Tip: If there are no people to chat with, invite a friend or open 2 browser windows.
The host is a windows console application which listens for incomming socket calls at port 4530.
//create the listening socket...
_socketListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, 4530);
//bind to local IP Address...
// Set the event to nonsignaled state.
// create the call back for any client connections...
_socketListener.BeginAccept(new AsyncCallback(OnClientConnect), null);
// Wait until a connection is made before continuing.
Our Silverlight chat client will connect to the host.
_endPoint = new DnsEndPoint(Application.Current.Host.Source.DnsSafeHost, 4530);
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.UserToken = _socket;
args.RemoteEndPoint = _endPoint;
args.Completed += new EventHandler<SocketAsyncEventArgs>(OnSocketConnectCompleted);
The Silverlight client is able to receive pushed messages from the server. But is also able to send messages to the server. The Server has to listen for incoming client messages and push those messages to all connected clients.
- Start Policy Server with GoGoGo.bat
- Start ChatHost
- Start the Silverlight page via the VISUAL STUDIO WEBSERVER (http://localhost:etc) and not via the file system (C:\etc)
Comments? Questions? E-mail me at firstname.lastname@example.org