I am unable to run a client/server program in php
        Posted  
        
            by 
                sibi
            
        on Super User
        
        See other posts from Super User
        
            or by sibi
        
        
        
        Published on 2012-09-29T00:43:20Z
        Indexed on 
            2012/09/29
            3:41 UTC
        
        
        Read the original article
        Hit count: 494
        
This is the program I am trying to run:
$host = "127.0.0.1";
$port = 25003;
// 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
$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
$input = socket_read($spawn, 1024) or die("Could not read input\n");
// clean up input string
$input = trim($input);
echo "Client Message : ".$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);
I enabled the PHP_socket option in WAMP but still I keep getting errors like unable to bind. Can someone please help me out?
© Super User or respective owner