![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
15/05/2011, 15:59
|
| | Fecha de Ingreso: mayo-2011
Mensajes: 49
Antigüedad: 13 años, 9 meses Puntos: 0 | |
Respuesta: socket o chat php????? bueno el código que he conseguido es el siguiente
************************************************** ********
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body bgcolor="#CCCCCC" text="#0000FF"
<title>BIENVENIDO <br></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
ESPERANDO CONEXION <br>
<?php
// ELIMITANDO EL TIEMPO LIMITE DE EJECUCIÓN DE UN SCRIPT (DEFAULT 30s)
set_time_limit(0);
ob_implicit_flush();
// DEFINIENDO VARIABLES
$host = "mi ip"; //ip del servidor
$puerto = "9500";
// ABRIENDO ARCHIVO DE LOG PARA LA ESCRITURA
// CREANDO EL SOCKET: (IP PROTOCOL[IPV4], TYPE SOCKET[TCP], PROTOCOL[TCP])
if (!$socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP)){
print "Fallo al iniciar el servidor paso1 \n";
exit;}
// ASOCIANDO HOST Y PUERTO AL SOCKET
if (!$bind = @socket_bind($socket, $host, $puerto)){
print "Fallo al iniciar el servidor paso2\n";
exit;}
// ESCUCHANDO LA CONEXIÓN DEL SOCKET
if (!$bind = @socket_listen($socket, 3)){
print "Fallo al iniciar el servidor paso3 \n";
exit;}
// ACEPTANDO LAS CONEXIONES SOCKET
//while (TRUE) {
if (!$accept = @socket_accept($socket)){
print "Fallo al aceptar conexiones paso4\n";}
echo "conexion realizada.<br>";
// MENSAJE DE ESTABLECIMIENTO DE CONEXIÓN
$buffer = "\nConexión realizada\n";
// ESCRIBIMOS EN EL SOCKET EL MENSAJE DE ESTABLECIMIENTO DE CONEXIÓN
if (!@socket_write($accept, $buffer)){
}
while(1){
$char=socket_read($accept,100);
echo "dato recibido $char .<br>";
if ($char=="+++")break;
}
//}
?>
</body>
</html>
************************************************** ****
la mayor parte es ctrl c y ctrl v pero ya entiendo la mayor parte del codigo ,el problema con este script es que solo acepta una conexión y tengo pensado tener unos 100 clientes conectados (dispositivos electrónicos ) a este socket y no se como discriminarlos y crear un canal de comunicación con cada uno.
espero haber sido claro .
gracias por la ayuda |