Exemplo n.º 1
0
        public string GetDocument(string serverIP, string documentName)
        {
            // retrieve requested document from the specified server
            // manage the session with the SD Server
            //  opening or resuming as needed
            // connect to and disconnect from the server w/in this method

            // make sure we have valid parameters
            // serverIP is the SD Server's IP address
            // documentName is the name of a docoument on the SD Server
            // both should not be empty
            if (String.IsNullOrWhiteSpace(serverIP) || String.IsNullOrWhiteSpace(documentName))
            {
                throw new Exception("EMpty server IP or document name!");
            }

            // contact the PRS and lookup port for "SD Server"
            PRSClient prs    = new PRSClient(prsIP, prsPort, "SD Server");
            ushort    sdPort = prs.LookupPort();

            // connect to SD server by ipAddr and port
            // use OpenOrResumeSession() to ensure session is handled correctly
            SDClient client = OpenOrResumeSession(serverIP, sdPort);

            // send get message to server for requested document
            string content = client.GetDocument(documentName);

            // disconnect from server
            client.Disconnect();

            // return the content
            return(content);
        }
Exemplo n.º 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();
        }