jason vorhees
2004-11-08 16:02:54 UTC
ciao a tutti,
propongo il mio spinoso problema sperando che qualche esperto riesca a
metterci una pezza perchè non ne vengo a capo! Sto cercando di capire
come funzionano i socket e ho preso un esempio base da un tutorial.
Il mio ambiente di sviluppo è Apache/1.3.27 (Win32) PHP/4.3.4
L'errore che ottengo il seguente:
"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 = 1135;
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);
?>
propongo il mio spinoso problema sperando che qualche esperto riesca a
metterci una pezza perchè non ne vengo a capo! Sto cercando di capire
come funzionano i socket e ho preso un esempio base da un tutorial.
Il mio ambiente di sviluppo è Apache/1.3.27 (Win32) PHP/4.3.4
L'errore che ottengo il seguente:
"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 = 1135;
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);
?>