|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Jul 2002
Messaggi: 202
|
[php] Problema con i socket
ciao a tutti,
sto facendo un po' di esercizi (sono proprio all'inizio oltre. Cosa significa questo warning? Grazie Warning: socket_listen() unable to listen on socket [10045]: Operazione richiesta non supportata per il tipo di oggetto indicato. in c:\programmi\apache group\apache\htdocs\test\socket\exercise.php3 on line 20 Could not set up socket listener Ecco il codice --- <? // set some variables $host = "127.0.0.1"; $port = 1234; // don't timeout! set_time_limit(0); // create socket (TCP socket) /*$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");*/ //If you wanted to create a UDP socket, you could use the following line of code instead $socket = socket_create(AF_INET, SOCK_DGRAM, 0) or die("Could not create socket\n"); // bind socket to port $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n"); // start listening for connections $result = socket_listen($socket, 1) or die("Could not set up socket listener\n"); // accept incoming connections // spawn another socket to handle communication $spawn = socket_accept($socket) or die("Could not accept incoming connection\n"); // read client input $input = socket_read($spawn, 1024) or die("Could not read input\n"); // clean up input string $input = trim($input); // reverse client input and send back $output = strrev($input) . "\n"; socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n"); // close sockets socket_close($spawn); socket_close($socket); ?> Grazie!! |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Dal manuale:
socket_listen() is applicable only to sockets of type SOCK_STREAM or SOCK_SEQPACKET. Quindi niente UDP...e direi ovviamente...perchè la struttura di un server UDP è diversa da quella di un server TCP... Non essendo UDP orientato alla connessione non puoi stare in attesa di una connessione (listen)...ma devi usare la funzione recvfrom... |
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Jul 2002
Messaggi: 202
|
Abuso della tua disponibilità
Ho provato a documentrmi al riguardo e adesso, correggendo il codice precedente, eseguo una connessione attraverso il protocollo tcp ma purtroppo ottengo un altro tipo di errore. Warning: socket_bind() unable to bind address [10048]: Di norma è consentito un solo utilizzo di ogni indirizzo di socket (protocollo/indirizzo di rete/porta). in c:\programmi\apache group\apache\htdocs\test\socket\exercise.php3 on line 12 Could not bind to socket Sembrerebbe esserci un altro servizio che sta utilizzando quella porta: ma allora come facco a determinare quella giusta? Grazie mille!! --- <? // set some variables $host = "127.0.0.1"; $port = 1234; set_time_limit(0); // create socket (TCP socket) $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); // bind socket to port $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n"); // start listening for connections $result = socket_listen($socket, 1) or die("Could not set up socket listener\n"); // accept incoming connections // spawn another socket to handle communication $spawn = socket_accept($socket) or die("Could not accept incoming connection\n"); // read client input $input = socket_read($spawn, 1024) or die("Could not read input\n"); // clean up input string $input = trim($input); // reverse client input and send back $output = strrev($input) . "\n"; socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n"); // close sockets socket_close($spawn); socket_close($socket); ?> Ultima modifica di utrecht : 02-11-2004 alle 16:03. |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
http://www.iana.org/assignments/port-numbers
Comunque strano che la porta sia già aperta...non è un servizio molto comune... |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 02:57.



















