[php]<?php
// set some variables
$host = "192.168.0.49";
$port = 10000;
echo '<pre>';
// don't timeout!
set_time_limit(0);
// create 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
do{
$result = socket_listen($socket, 3) 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
echo "Waiting for connection ";
$input = socket_read($spawn, 1024) or die("Could not read input\n");
if($input == "END") {
socket_write($spawn, "Socket terminated", 25) or die("Could not write
output\n");
break;
}
echo "Client COnnected with string '$input' \n";
// clean up input string
$input = trim($input);
// reverse client input and send back
$output = strrev($input) . "\n";
echo "OutPut sent " .$output;
socket_write($spawn, $output, strlen ($output)) or die("Could not write
output\n");
// close sockets
}while(true);
socket_close($spawn);
socket_close($socket);
echo "\n\nSocket terminated\n";
?>[/php]
I Am Getting Error:
socket_bind() [function.socket-bind]: unable to bind address [0]: Only one usage of each socket address (protocol/network address/port) is normally permitted.
How To Resolve It
Please Help