Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/05/2010, 11:59
Avatar de kuroro_lucifer
kuroro_lucifer
 
Fecha de Ingreso: noviembre-2009
Mensajes: 8
Antigüedad: 14 años, 5 meses
Puntos: 0
problema con conexion fsockopen

Mi problema esta en la conexion al fsockopen creo ke la estoy mal !!

el punto es que antes trabajaba con la conexion afuera del metodo firstchannelidle y ahora necesito usarla dentro, y no me funciona , tampoco da error de codigo


si alguien me puede ayudar de ante mano gracias.

Código:
class hyper
{


//##################################################################################################
	//variable que contiene la conexion
	var $hghandle;
//##################################################################################################
	//establece la conexion a hypergateway
	

	function hyper($host, $port) //constructor de la clase
	{
		$this->hghandle = fsockopen($host, $port, &$errno, &$errstr, 10);
		if(!$this->hghandle) 
		{
			return false;
		}
		else
		{
			return true;
		}   

	}

//##################################################################################################
	
	
	//autentifica la sesion con hypergateway
	function auth($pass)
	{
		fwrite($this->hghandle,"PASS $pass\r\n");
		$response = fgets($this->hghandle, 1024);
		$resp = split(" ", $response);

		switch($resp[0])
		{
			case "Authenticated":
				return true;
				break;
			case "AuthError":
				return false;
				break;
		}
		
	}
	
//##################################################################################################

	//devuelve el primer canal disponible para llamada desde el array
	function firstchannelidle($arritems)
	{

		
		$chan="no conexion";
		for($i=0; $i<count($arritems) && $chan==false; $i++)
		{

		$item = $arritems[$i];
		$host=$item->_tIp;
		$port="8887";		
		$pass=$item->_pass;
		$slotitem = $item->_slot;
		
		//-------------------------------------------------------------------
		
		$this->hyper($host, $port);
		$this->auth($pass);
	
		//--------------------------------------------------------------------
			
			
			fwrite($this->hghandle,"GetStatus /I124/M0/A$slotitem\r\n");
			$response = fgets($this->hghandle, 1024);
			$resp = split(" ", $response);
			
		

			if($resp[0]=="Status")
			{		
				if($slot=$this->GetSection($resp[1], "g"))
				{
					$sims=explode(",", $slot);
					$mod=($item->_channel % 4)-1;
					if($sims[$mod]=="00")
					{
						$chan=$item->_channel;
					}
				}
			}
			
		//cerrar conexion
		
		fclose($this->hghandle);	
		
		}
		
		return $chan ;//
	}

//##################################################################################################

	//finaliza la conexion a hypergateway
	function close()
	{
		if($this->hghandle) 
		{
			fclose($this->hghandle);
		}
	}
//###################################################################################################


	//devuelve la seccion requerida desde una repuesta de hypergateway
	function GetSection($strMessage, $strSectionName)
	{
		$nTagLen = strlen($strSectionName);
		$Params = explode("/", $strMessage);
		$strParam = false;
		for ($i=0; $i<count($Params) && $strParam==false; $i++)
		{
		    if (substr($Params[$i], 0, $nTagLen)==$strSectionName)
		    {
			$strParam=substr($Params[$i], $nTagLen);
		    }
		}
		return $strParam;
	}

//##################################################################################################

	function GetValidateSlot($channel)// obtener el slot y posicion del simcard segun canal
	{

	$valor=20+($channel/4);
	$valor=round($valor);
	$resto=($channel%4);

        if($resto>0 && $resto<2)
        {
            $valor=$valor+1;
        }


	$resto=($channel%4);
        if($resto==0)
        {
           $resto=4;
        }

	$validacion[0]=$valor;
	$validacion[1]=$resto;

	return array($validacion);

	}

//##################################################################################################

	function GetActiveSIM($slot,$resto)//obtener posicion del simcard
	{
	
			fwrite($this->hghandle,"SetMultiSIM /Q/A$slot/I919\r\n");

			$response = fgets($this->hghandle, 1024);
			$resp = split("/", $response);
			
			$posiciones=$resp[3];
			
			$posiciones=substr($posiciones,1);
			$posiciones= split(",", $posiciones);			
			
			$posicion=$posiciones[$resto-1];
			
			return $posicion;
	
	}


} //fin clase hyper


pero si lo llamo desde otro php funciona okey


Código:
	
			//consultar primer canal disponible a hypergateway
			//if($hyper=new hyper($hghost, $hgport))
			//{
			//	if($hyper->auth($hgpass))
			//	{
			//		if(
				$hyper=new hyper();
				$chan=$hyper->firstchannelidle($hgarray);//prueba($hgarray)//
			//		{
						$chan_id=$chan;
			//		}
			//	}
			//	$hyper->close();
			//}