Handling the Server Lost Event

The last thing you will need to cover is ensuring that the client can react correctly if the server is lost. You've handled this in the peer-to-peer session already, and the code here is identical. First, you add a hook for the SessionTerminated event:

connection.SessionTerminated += new
    SessionTerminatedEventHandler(OnSessionTerminate);

Plus you'll need the actual event handler:

 private void OnSessionTerminate(object sender, SessionTerminatedEventArgs e) { this.BeginInvoke(new DisconnectCallback(OnDisconnect), null); } private void OnDisconnect() { EnableSendDataButtons(false); AddText("Session terminated."); connected = false; // Dispose of our connection, and set it to null connection.Dispose(); connection ...

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.