private void Form1_Closing(object sender, EventArgs e)//Form closing { if (SDSessions.Count > 0) { foreach (KeyValuePair <string, SDClient> pair in SDSessions) { string serverIP = pair.Key; SDClient client = pair.Value; try { client.CloseSession(); } catch (Exception ex) { MessageBox.Show("Failed to close session to server:" + serverIP + ", error: " + ex.Message); } } } }
public void Close() { // close each open session with the various servers // for each session... foreach (SDSession session in sessions.Values) { // connect to the SD Server's IP address and port SDClient client = new SDClient(session.ipAddr, session.port); client.Connect(); // send the close for this sessionId client.SessionID = session.sessionId; client.CloseSession(); // disconnect from server client.Disconnect(); } sessions.Clear(); }