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 = null; } 

All you really want to do in this scenario is make sure you dispose the connection and nullify the object. However, it's good practice to inform the user by updating the UI and disabling the buttons.



Managed DirectX 9 Graphics and Game Programming, Kick Start
Managed DirectX 9 Kick Start: Graphics and Game Programming
ISBN: B003D7JUW6
EAN: N/A
Year: 2002
Pages: 180
Authors: Tom Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net