예제 #1
0
        public string RequestControllerName(string address)
        {
            // If we cached the address already: return the controller name
            if (_controllerNameCache.ContainsKey(address))
            {
                return(_controllerNameCache[address]);
            }


            try
            {
                // Connect to the interface
                var ipEndPoint = new IPEndPoint(IPAddress.Parse(address), TxtInterface.ControllerIpPort);
                var socket     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                {
                    SendTimeout    = 1000,
                    ReceiveTimeout = 1000
                };
                socket.Connect(ipEndPoint);


                // Send the command
                socket.Send(new CommandQueryStatus().GetByteArray());

                var response = new ResponseQueryStatus();

                var responseBytes = new byte[response.GetResponseLength()];


                // Receive the response
                Receive(socket, responseBytes, responseBytes.Length);

                // Close the socket
                socket.Shutdown(SocketShutdown.Both);
                socket.Close();
                socket.Dispose();

                // Process the response
                response.FromByteArray(responseBytes);

                _controllerNameCache.Add(address, response.GetControllerName());

                return(response.GetControllerName());
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
예제 #2
0
        public string GetInterfaceName()
        {
            ThrowWhenNotConnected();

            try
            {
                var responseQueryStatus = new ResponseQueryStatus();
                TxtCommunication.SendCommand(new CommandQueryStatus(), responseQueryStatus);
                return(responseQueryStatus.GetControllerName());
            }
            catch (Exception e)
            {
                HandleException(e);
            }
            return(string.Empty);
        }