Archived
This forum has been archived. Please start a new discussion on GitHub.
Slice Host Checking
Hello friends,
how can i check with php, if a slice host from a remote server sends a answer and works.
I would like to implement a slice-host check function!
Info:
If you have a existing and working Slice interface configured.
Thanks,
P.M.
how can i check with php, if a slice host from a remote server sends a answer and works.
I would like to implement a slice-host check function!
Info:
If you have a existing and working Slice interface configured.
Thanks,
P.M.
0
Comments
-
Hi Michael
Isn't clear what you want to do, can you clarify what you want to do?
Regards,
Jose0 -
As you may know iam developing a webinterface for mumble. Now i want to add multi-host-support for slice. So i simply want to check if a ip like 83.169.42.43 answers correctly and my plugin can use this host, whitout getting a exception or smtg. like this!
I hope my request is clear now.
Thanks!!!0 -
You need to create a proxy with that host in the endpoints and then use ice_ping to check if the server/object is alive. If ice_ping returns without exceptions you can consider it alive.0
-
Example needed
Okay Somethg. like this? I am not shure with the ping arguments:
[PHP]
try {
$_BASE = $ICE->stringToProxy("Meta:tcp -h ".$SliceHost." -p ".$SlicePort."");
$_SLICE = $_BASE->ice_ping("::Murmur::Meta");
} catch (Ice_Exception $error) {
echo $error->e;
}
[/PHP]
$SliceHost and $SlicePort are the values i need to validate!
Thanks!0 -
Allmost but ice_ping doesn't receive any parameters
[PHP]
try {
$_BASE = $ICE->stringToProxy("Meta:tcp -h ".$SliceHost." -p ".$SlicePort."");
$_BASE->ice_ping();
} catch (Ice_Exception $error) {
echo $error->e;
}
[/PHP]
You can also use a checked cast in that case.
[PHP]
try {
$_BASE = $ICE->stringToProxy("Meta:tcp -h ".$SliceHost." -p ".$SlicePort."");
$_SLICE = $_BASE->ice_checkedCast("::Murmur::Meta");
} catch (Ice_Exception $error) {
echo $error->e;
}
[/PHP]
Note that ice_checkedCast does a remote invocation, so when it returns you know that the object is alive and has the expected type.
Both will work, the later is safer in case you have doubts if the object implements the required interface.0 -
Result
Okay.
So the following should give me a message if it works or not. ??
My question is related to the value $_SLICE, so is the Return Value TRUE/FALSE ?
[PHP]
try {
$_BASE = $ICE->stringToProxy("Meta:tcp -h ".$SliceHost." -p ".$SlicePort."");
$_SLICE = $_BASE->ice_checkedCast("::Murmur::Meta");
if ($_SLICE) {
echo 'It works!';
} else {
echo 'Something went wrong!';
}
} catch (Ice_Exception $error) {
echo $error->e;
echo 'Something went wrong!';
}
[/PHP]0 -
If checkedCast success it returns a proxy of the given type, if fails it returns a null proxy, so the comparisons will work as null == 0 == false in PHP.
Note that you can use the proxy helpers to do the checked cast, this is preferred than pass the type as strings to avoid typos.
[PHP]
try {
$_BASE = $ICE->stringToProxy("Meta:tcp -h ".$SliceHost." -p ".$SlicePort."");
$_SLICE = Mumur_MetaPrxHelper::checkedCast($_BASE);
if ($_SLICE) {
echo 'It works!';
} else {
echo 'Something went wrong!';
}
} catch (Ice_Exception $error) {
echo $error->e;
echo 'Something went wrong!';
}
[/PHP]
See also PHP Mapping for Interfaces - Casting Proxies in PHP0 -
Hello Jose,
Thank you very much!
I have used a simple more extract code like the following in my plugin:
[PHP]
try {
$secure = array('secret' => $ice_secure);
$_BASE = $ICE->stringToProxy("Meta:tcp -h ".$SliceHost." -p ".$SlicePort."");
$_SLICE = $_BASE->ice_checkedCast("::Murmur::Meta")->ice_context($secure);
if ($_SLICE) {
echo 'It works!';
} else {
echo 'Something went wrong!';
}
} catch (Ice_Exception $error) {
echo $error->e;
echo 'Something went wrong!';
}
[/PHP]
This works great! Have a nice day!
Michael0 -
Need help for Ice Connect 3.4.2
Hello friends again.
I need your help! I am developing with 3.3.1. And now iam getting on a server with 3.4.2 some trouble with the following code:
[PHP]
if (extension_loaded('ice')) {
//Load Slice Interface if Slice-Version >= 3.4.x
if (function_exists('Ice_intVersion') && Ice_intVersion() > 30400) {
try {
//Slice 3.4.x
include_once('../inc/resources/php/framework_classes_slice_3.4.x.php');
include_once('../inc/resources/php/framework_classes_murmur_1.2.4.php');
//Initialisiere Slice >= 3.4.x
$initData = new Ice_InitializationData;
$initData->properties = Ice_createProperties();
$initData->properties->setProperty('Ice.ImplicitContext', 'Shared');
$ICE = Ice_initialize($initData);
//Definiere Murmur Host
$_SLICE = Murmur_MetaPrxHelper::checkedCast($ICE->stringToProxy("Meta:tcp -h ".$SliceHost." -p ".$SlicePort.""))->ice_context($SliceSecret);
//Setze Slice-Secret von Murmur
$_SLICE->icesecret = $SliceSecret;
} catch (Ice_ConnectionRefusedException $error) {
$_SLICE_ERR = TRUE;
}
} else {
//Load Slice Interface if Slice-Version <= 3.3.1
//Initialisiere Slice <= 3.3.x
Ice_loadProfile();
//Definiere Murmur Host
$_BASE = $ICE->stringToProxy("Meta:tcp -h ".$SliceHost." -p ".$SlicePort."");
$_SLICE = $_BASE->ice_checkedCast("::Murmur::Meta")->ice_context($SliceSecret);
//Set Slice-Secret of Murmur
$_SLICE->icesecret = $SliceSecret;
}
} else {
$_SLICE_ERR = TRUE;
}
[/PHP]
I think my problem is the icesecret for 3.4? Is the connecting to 3.4. correctly?
Thanks!0 -
I don't see anything wrong with your code, are you getting any exceptions or PHP errors? seeing that could help to determine what is the problem.
A few notes about your code:-
Ice.ImplicitContext are not supported by PHP so setting this property has not effect, you can simplify the communicator initialization:
[PHP]$ICE = Ice_initialize();[/PHP]
-
[PHP]$_SLICE->icesecret = $SliceSecret[/PHP]
That isn't incorrect, but will be better to not put your data in the generated proxies objects, you can access the context using ice_getContext, so don't need to keep another reference around.
0