downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

stream_socket_client> <stream_set_write_buffer
Last updated: Fri, 14 Aug 2009

view this page in

stream_socket_accept

(PHP 5)

stream_socket_acceptAccepte une connexion sur une socket créée par stream_socket_server()

Description

resource stream_socket_accept ( resource $server_socket [, float $timeout= ini_get("default_socket_timeout") [, string &$peername ]] )

Accepte une connexion sur une socket créée précédemment avec stream_socket_server().

Liste de paramètres

timeout

Remplace le délai d'expiration par défaut de la socket. Ce délai doit être donné en secondes.

peername

Le nom (adresse) du client connecté, si fourni et si disponible pour le transport sélectionné.

Note: Peut également être déterminé plus tard, en utilisant la fonction stream_socket_get_name().

Valeurs de retour

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.

Notes

Avertissement

Cette fonction ne doit pas être utilisée avec les sockets serveur UDP. À la place, utilisez les fonctions stream_socket_recvfrom() et stream_socket_sendto().

Voir aussi



stream_socket_client> <stream_set_write_buffer
Last updated: Fri, 14 Aug 2009
 
add a note add a note User Contributed Notes
stream_socket_accept
fred dot hakeem dot smith at muslimamerica dot bob dot net
02-Jan-2008 08:33
To whom it may concern, and it may concern you greatly, stream_set_blocking has no effect on stream_socket_accept.
If you want it to return right away, connection or not, use 0 for the timeout parameter.
mickael dot bailly at free dot fr
18-Jul-2006 10:10
this function, compared to the function socket_accept, got an extra argument "timeout".
To make this function wait indefinitelly to incoming connections, just as in socket_accept, set timeout to -1. It works for me with PHP 5.0.4.
leleu256NOSPAM at hotmail dot com
02-Nov-2004 01:58
This code could be very helpfull...

The following code is for the "server". It listen for a message until CTRL-C

<?php
while (true)
{
// disconnected every 5 seconds...
receive_message('127.0.0.1','85',5);
}

function
receive_message($ipServer,$portNumber,$nbSecondsIdle)
{
 
// creating the socket...
 
$socket = stream_socket_server('tcp://'.$ipServer.':'.$portNumber, $errno, $errstr);
  if (!
$socket)
  {
    echo
"$errstr ($errno)<br />\n";
  }
  else
   {
   
// while there is connection, i'll receive it... if I didn't receive a message within $nbSecondsIdle seconds, the following function will stop.
   
while ($conn = @stream_socket_accept($socket,$nbSecondsIdle))
    {
    
$message= fread($conn, 1024);
     echo
'I have received that : '.$message;
    
fputs ($conn, "OK\n");
    
fclose ($conn);
    }
   
fclose($socket);
  }
}
?>

The following code is for the "client". It send a message, and read the respons...

<?php

send_message
('127.0.0.1','85','Message to send...');

function
send_message($ipServer,$portServer,$message)
{
 
$fp = stream_socket_client("tcp://$ipServer:$portServer", $errno, $errstr);
  if (!
$fp)
  {
     echo
"ERREUR : $errno - $errstr<br />\n";
  }
  else
  {
    
fwrite($fp,"$message\n");
    
$response fread($fp, 4);
     if (
$response != "OK\n")
        {echo
'The command couldn\'t be executed...\ncause :'.$response;}
     else
        {echo
'Execution successfull...';}
    
fclose($fp);
  }
}
?>

stream_socket_client> <stream_set_write_buffer
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites