cvs: phpdoc-it /reference/sockets reference.xml /reference/sockets/functions socket-clear-error.xml socket-connect.xml socket-getpeername.xml
socket-getsockname.xml socket-last-error.xml

From: Date: Sun, 11 Jan 2004 20:17:16 +0000
Subject: cvs: phpdoc-it /reference/sockets reference.xml /reference/sockets/functions socket-clear-error.xml socket-connect.xml socket-getpeername.xml
socket-getsockname.xml socket-last-error.xml
Groups: php.doc.it 
Request: Send a blank email to doc-it+get-504@lists.php.net to get a copy of this message
darvina Sun Jan 11 15:17:16 2004 EDT Modified files: /phpdoc-it/reference/sockets reference.xml /phpdoc-it/reference/sockets/functions socket-clear-error.xml socket-connect.xml socket-getpeername.xml socket-getsockname.xml socket-last-error.xml Log: Sync to En tree

Index: phpdoc-it/reference/sockets/reference.xml diff -u phpdoc-it/reference/sockets/reference.xml:1.9 phpdoc-it/reference/sockets/reference.xml:1.10 --- phpdoc-it/reference/sockets/reference.xml:1.9 Fri Oct 3 15:27:46 2003 +++ phpdoc-it/reference/sockets/reference.xml Sun Jan 11 15:17:15 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- EN-Revision: 1.10 Maintainer: darvina Status: ready --> +<!-- EN-Revision: 1.17 Maintainer: darvina Status: ready --> <reference id="ref.sockets"> <title>Funzioni relative ai Socket</title> <titleabbrev>Sockets</titleabbrev> @@ -31,7 +31,7 @@ trovare utili informazioni nelle pagine del manuale di Unix, ed inoltre sul web si può trovare diversi tutorial sulla programmazione dei socket in C, molti dei quali possono essere utilizzati, con - lievi modifiche, nella programmazione dei socket in PHP. Il link <ulink url="&url.socket.faq;">UNIX Socket + lievi modifiche, nella programmazione dei socket in PHP. Il link <ulink url="&url.socket.faq;">Unix Socket FAQ</ulink> può essere un buon punto di partenza. </para> &warn.experimental; @@ -105,28 +105,28 @@ <![CDATA[ #!/usr/local/bin/php -q <?php -error_reporting (E_ALL); +error_reporting(E_ALL); /* Si indica allo script di non uscire mentre attende una connessione */ -set_time_limit (0); +set_time_limit(0); /* Abilita lo scarico dell'output così si è in grado di vedere cosa passa * non appena arrivano i dati al server. */ -ob_implicit_flush (); +ob_implicit_flush(); $address = '192.168.1.53'; $port = 10000; -if (($sock = socket_create (AF_INET, SOCK_STREAM, 0)) < 0) { - echo "socket_create() fallito: motivo: " . socket_strerror ($sock) . "\n"; +if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) { + echo "socket_create() fallito: motivo: " . socket_strerror($sock) . "\n"; } -if (($ret = socket_bind ($sock, $address, $port)) < 0) { - echo "socket_bind() fallito: motivo: " . socket_strerror ($ret) . "\n"; +if (($ret = socket_bind($sock, $address, $port)) < 0) { + echo "socket_bind() fallito: motivo: " . socket_strerror($ret) . "\n"; } -if (($ret = socket_listen ($sock, 5)) < 0) { - echo "socket_listen() fallito: motivo: " . socket_strerror ($ret) . "\n"; +if (($ret = socket_listen($sock, 5)) < 0) { + echo "socket_listen() fallito: motivo: " . socket_strerror($ret) . "\n"; } do { @@ -140,28 +140,28 @@ socket_write($msgsock, $msg, strlen($msg)); do { - if (FALSE === ($buf = socket_read ($msgsock, 2048, PHP_NORMAL_READ))) { - echo "socket_read() fallito: motivo: " . socket_strerror ($ret) . "\n"; + if (FALSE === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) { + echo "socket_read() fallito: motivo: " . socket_strerror($ret) . "\n"; break 2; } - if (!$buf = trim ($buf)) { + if (!$buf = trim($buf)) { continue; } if ($buf == 'quit') { break; } if ($buf == 'shutdown') { - socket_close ($msgsock); + socket_close($msgsock); break 2; } $talkback = "PHP: Testo scritto '$buf'.\n"; - socket_write ($msgsock, $talkback, strlen ($talkback)); + socket_write($msgsock, $talkback, strlen $talkback)); echo "$buf\n"; } while (true); - socket_close ($msgsock); + socket_close($msgsock); } while (true); -socket_close ($sock); +socket_close($sock); ?> ]]> </programlisting> @@ -175,49 +175,50 @@ molto semplicemente, si collega ad un server, invia una richiesta HEAD, visualizza la risposta ed esce. </para> - <programlisting> + <programlisting role="php"> <![CDATA[ <?php -error_reporting (E_ALL); +error_reporting(E_ALL); echo "<h2>Connessione TCP/IP </h2>\n"; /* Ottiene la porta per il servizio WWW. */ -$service_port = getservbyname ('www', 'tcp'); +$service_port = getservbyname('www', 'tcp'); /* Ottiene l'indirizzo IP per il server cercato. */ -$address = gethostbyname ('www.php.net'); +$address = gethostbyname('www.php.net'); /* Crea un socket TCP/IP. */ -$socket = socket_create (AF_INET, SOCK_STREAM, 0); +$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket < 0) { - echo "socket_create() fallito: motivo: " . socket_strerror ($socket) . "\n"; + echo "socket_create() fallito: motivo: " . socket_strerror($socket) . "\n"; } else { echo "OK.\n"; } echo "Tentativo di connessione a '$address' sulla porta '$service_port'..."; -$result = socket_connect ($socket, $address, $service_port); +$result = socket_connect($socket, $address, $service_port); if ($result < 0) { echo "socket_connect() fallito.\nMotivo: ($result) " . socket_strerror($result) . "\n"; } else { echo "OK.\n"; } - -$in = "HEAD / HTTP/1.0\r\n\r\n"; +$in = "HEAD / HTTP/1.1\r\n"; +$in .= "Host: www.example.com\r\n"; +$in .= "Connection: Close\r\n\r\n"; $out = ''; echo "Invio HTTP HEAD..."; -socket_write ($socket, $in, strlen ($in)); +socket_write($socket, $in, strlen ($in)); echo "OK.\n"; echo "Lettura della risposta:\n\n"; -while ($out = socket_read ($socket, 2048)) { +while ($out = socket_read($socket, 2048)) { echo $out; } echo "Chiusura del socket..."; -socket_close ($socket); +socket_close($socket); echo "OK.\n\n"; ?> ]]> Index: phpdoc-it/reference/sockets/functions/socket-clear-error.xml diff -u phpdoc-it/reference/sockets/functions/socket-clear-error.xml:1.1 phpdoc-it/reference/sockets/functions/socket-clear-error.xml:1.2 --- phpdoc-it/reference/sockets/functions/socket-clear-error.xml:1.1 Mon Jun 17 16:37:37 2002 +++ phpdoc-it/reference/sockets/functions/socket-clear-error.xml Sun Jan 11 15:17:16 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- EN-Revision: 1.4 Maintainer: darvina Status: ready --> +<!-- EN-Revision: 1.5 Maintainer: darvina Status: ready --> <refentry id="function.socket-clear-error"> <refnamediv> <refname>socket_clear_error</refname> Index: phpdoc-it/reference/sockets/functions/socket-connect.xml diff -u phpdoc-it/reference/sockets/functions/socket-connect.xml:1.4 phpdoc-it/reference/sockets/functions/socket-connect.xml:1.5 --- phpdoc-it/reference/sockets/functions/socket-connect.xml:1.4 Sun Jun 2 08:41:04 2002 +++ phpdoc-it/reference/sockets/functions/socket-connect.xml Sun Jan 11 15:17:16 2004 @@ -1,8 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> <!-- splitted from ./it/functions/sockets.xml, last change in rev 1.4 --> -<!-- last change to 'socket-connect' in en/ tree in rev 1.1 --> -<!-- EN-Revision: 1.4 Maintainer: darvina Status: ready --> -<!-- OLD-Revision: 1.34/EN.1.1 --> +<!-- EN-Revision: 1.5 Maintainer: darvina Status: ready --> <refentry id="function.socket-connect"> <refnamediv> <refname>socket_connect</refname> Index: phpdoc-it/reference/sockets/functions/socket-getpeername.xml diff -u phpdoc-it/reference/sockets/functions/socket-getpeername.xml:1.4 phpdoc-it/reference/sockets/functions/socket-getpeername.xml:1.5 --- phpdoc-it/reference/sockets/functions/socket-getpeername.xml:1.4 Mon May 5 15:52:46 2003 +++ phpdoc-it/reference/sockets/functions/socket-getpeername.xml Sun Jan 11 15:17:16 2004 @@ -1,8 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> <!-- splitted from ./it/functions/sockets.xml, last change in rev 1.4 --> -<!-- last change to 'socket-getpeername' in en/ tree in rev 1.27 --> -<!-- EN-Revision: 1.6 Maintainer: darvina Status: ready --> -<!-- OLD-Revision: 1.34/EN.1.27 --> +<!-- EN-Revision: 1.7 Maintainer: darvina Status: ready --> <refentry id="function.socket-getpeername"> <refnamediv> <refname>socket_getpeername</refname> Index: phpdoc-it/reference/sockets/functions/socket-getsockname.xml diff -u phpdoc-it/reference/sockets/functions/socket-getsockname.xml:1.4 phpdoc-it/reference/sockets/functions/socket-getsockname.xml:1.5 --- phpdoc-it/reference/sockets/functions/socket-getsockname.xml:1.4 Mon May 5 15:52:46 2003 +++ phpdoc-it/reference/sockets/functions/socket-getsockname.xml Sun Jan 11 15:17:16 2004 @@ -1,8 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> <!-- splitted from ./it/functions/sockets.xml, last change in rev 1.4 --> -<!-- last change to 'socket-getsockname' in en/ tree in rev 1.27 --> -<!-- EN-Revision: 1.4 Maintainer: darvina Status: ready --> -<!-- OLD-Revision: 1.34/EN.1.27 --> +<!-- EN-Revision: 1.5 Maintainer: darvina Status: ready --> <refentry id="function.socket-getsockname"> <refnamediv> <refname>socket_getsockname</refname> Index: phpdoc-it/reference/sockets/functions/socket-last-error.xml diff -u phpdoc-it/reference/sockets/functions/socket-last-error.xml:1.4 phpdoc-it/reference/sockets/functions/socket-last-error.xml:1.5 --- phpdoc-it/reference/sockets/functions/socket-last-error.xml:1.4 Fri Oct 3 15:27:47 2003 +++ phpdoc-it/reference/sockets/functions/socket-last-error.xml Sun Jan 11 15:17:16 2004 @@ -1,8 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> <!-- splitted from ./it/functions/sockets.xml, last change in rev 1.1 --> -<!-- last change to 'socket-last-error' in en/ tree in rev 1.1 --> -<!-- EN-Revision: 1.5 Maintainer: darvina Status: ready --> -<!-- OLD-Revision: 1.34/EN.1.1 --> +<!-- EN-Revision: 1.6 Maintainer: darvina Status: ready --> <refentry id="function.socket-last-error"> <refnamediv> <refname>socket_last_error</refname>
« previous php.doc.it (#504) next »