PHP Classes

File: README.es

Recommend this page to a friend!
  Classes of markitos   msocket   README.es   Download  
File: README.es
Role: ???
Content type: text/plain
Description: spanish readme file
Class: msocket
Simple class to use php sockets
Author: By
Last change:
Date: 21 years ago
Size: 2,765 bytes
 

Contents

Class file image Download
README FILE MSOCKET ................... Msocket es una sencilla clase de socket PHP para la conexion directa a hosts remotos, o locales :) Bastara con instanciar la clase pasandole el host con el que queremos conectar: $MSocket = new msocket ("www.google.com"); Una vez instanciada la clase, podemos enviar datos de dos maneras: 1. Manteniendo el socket abierto. Para ello usaremos los metodos Envia y Recibe: $MSocket = new msocket ("localhost"); $MSocket->Envia ("POST /formproc.php HTTP/1.1\n"); $MSocket->Envia ("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\n"); $MSocket->Envia ("Host: localhost\n"); $MSocket->Envia ("Referer: http://localhost/index.html\n"); $MSocket->Envia ("User_Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\n"); $MSocket->Envia ("Content-Length: 18\n"); $MSocket->Envia ("Content-Type: application/x-www-form-urlencoded\n"); $MSocket->Envia ("Accept_encoding: gzip, deflate\n"); $MSocket->Envia ("Connection: Close\n"); $MSocket->Envia ("\n"); $MSocket->Envia ("DATA=<DATOS></DATOS>\n"); $DatosRecibidos = $MSocket->Recibe(); , o bien... 2. Abriendo el socket, enviando datos y cerrando. Para lo que usaremos un unico metodo: EnviaRecibe: $MSocket = new msocket ("localhost"); $DatosEnvio = "POST /formproc.php HTTP/1.1\n"; $DatosEnvio.= "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\n"; $DatosEnvio.= "Host: localhost\n"; $DatosEnvio.= "Referer: http://localhost/index.html\n"; $DatosEnvio.= "User_Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\n"; $DatosEnvio.= "Content-Length: 18\n"; $DatosEnvio.= "Content-Type: application/x-www-form-urlencoded\n"; $DatosEnvio.= "Accept_encoding: gzip, deflate\n"; $DatosEnvio.= "Connection: Close\n"; $DatosEnvio.= "\n"; $DatosEnvio.= "DATA=<DATOS></DATOS>\n"; $DatosRecibidos = $MSocket->EnviaRecibe ($DatosEnvio); La diferencia entre forma y otra es que de la primera, abrimos el socket y este no se cierra hasta que recibimos los datos, por lo que podemos mantenerlo abierto , por ejemplo, para hacer un POST emulando un formulario. Si se desea, modificar la clase para que lo mantenga abierto al recibir es trivial, bastara con reemplazar el metodo Recibe de la siguiente manera: function Recibe() { $Retorno=''; if (!$this->Socket){ return $Retorno; } while (!feof ($this->Socket)) {$Retorno .= fgets ($this->Socket, 4096);} //$this->_Desconecta(); return $Retorno; } , despues de terminar el uso, se puede o bien llamar a _Desconecta, o.., pasando de todo, un unset ($Msocket) :P Para cualquier duda o aclaracion mailme: contacto@markitos.net ;. ;. markitos.net ;. mArKitos 2oo2 ;.