Пример #1
0
        private SDClient OpenOrResumeSession(string ipAddr, ushort port)
        {
            // create and connect an SDClient instance to the given SD Server
            // open or resume a session
            // leave the SDClient connected and return it for communication to the server

            // Create SDClient and connect to the server
            // connect to the SD Server's IP address and port
            SDClient client = new SDClient(ipAddr, port);

            client.Connect();

            // do we already have a session for this server?
            if (sessions.ContainsKey(ipAddr))
            {
                // yes, session already open
                // retrieve the sessionId and send resume message to server
                ulong sessionId = sessions[ipAddr].sessionId;

                // Resume the session on the server
                client.ResumeSession(sessionId);
            }
            else
            {
                // no, session not open for this server
                // open a new session and save the sessionId
                client.OpenSession();

                // save this open session in the sessions dictionary for later
                sessions[ipAddr] = new SDSession(ipAddr, port, client.SessionID);
            }

            // keep the client open and return it
            return(client);
        }
Пример #2
0
        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();
        }