Making the Client React

It's clear now that the client will also need to hook the receive data event since you've updated the server to actually send data as well. Add the same hook you used for the server into your client application. The actual event handler for the client will be similar as well. Add the event handler found in Listing 19.7 to your client application.

Listing 19.7. Handling Received Data on the Client
 private void OnDataReceive(object sender, ReceiveEventArgs e) { NetworkMessages msg = (NetworkMessages)e.Message.ReceiveData.Read (typeof(NetworkMessages)); string newtext = string.Empty; int playerID = 0; switch (msg) { case NetworkMessages.ChangeName: playerID = (int)e.Message.ReceiveData.Read(typeof(int)); string newname = ...

Get Managed DirectX® 9 Kick Start: Graphics and Game Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.