/// <summary> /// Connect to ICE interface on running Murmur server /// </summary> /// <param name="address">murmur server address</param> /// <param name="port">ice port</param> /// <param name="secret">ice password</param> /// <param name="timeout"></param> /// <returns>object of murmur server</returns> public MetaPrx Connect(string address, int port, string secret, string callbackAddress = "127.0.0.1", int callbackPort = 0, int timeout = 1000) { this.timeout = timeout; // initialize run(new string[] { }); ic = Ice.Util.initialize(_data); // set ice secret if (!string.IsNullOrEmpty(secret)) { ic.getImplicitContext().put("secret", secret); } try { var connectionString = string.Format("Meta:tcp -h {0} -p {1} -t {2}", address, port, timeout); // Create a proxy var obj = ic.stringToProxy(connectionString); // Tests whether the target object of this proxy can be reached. obj.ice_ping(); // initialize metadata of murmur server _meta = MetaPrxHelper.uncheckedCast(obj); var portString = (callbackPort > 0) ? string.Format("-p {0}", callbackPort) : ""; var connectionStringCB = string.Format("tcp -h {0} {1} -t {2}", callbackAddress, portString, timeout); // Create the callback adapter ic.getProperties().setProperty("Ice.PrintAdapterReady", "0"); _adapter = ic.createObjectAdapterWithEndpoints("Callback.Client", connectionStringCB); _adapter.activate(); _meta.ice_ping(); } catch (System.Exception e) { Console.WriteLine(e.ToString()); throw new MurmurPlugin.ConnectionRefusedException(); } // FIXME: check for valid ice secret, because getLogLen() is working only if "icesecretwrite" is valid // (there a secure hole - get methods allowed if "icesecretread" is not set) // if secret is invalid it throws UnmarshalOutOfBoundsException(); try { // set allowhtml property to the server to check ice writesecret _meta.getAllServers()[0].setConf("allowhtml", "true"); } catch { throw new MurmurPlugin.InvalidSecretException(); } return(_meta); }
/// <summary> /// Check connection is estabilished or not /// </summary> public bool IsConnected() { try { _meta.ice_ping(); return(true); } catch (Exception) { return(false); } }