handle muliple clients in php socket server-udp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samyphp
    New Member
    • Jul 2007
    • 3

    handle muliple clients in php socket server-udp

    i am trying to broadcast continuous data from server using udp connection...
    while accessing from single client its working fine...
    but while accessing from multiple clients its not working and throwing an error like

    Warning: socket_bind() [function.socket-bind]: unable to bind address [0]: Only one usage of each socket address (protocol/network address/port) is normally permitted. in C:\xampp\htdocs \socket\client1 .php on line 16

    Warning: socket_recvfrom () [function.socket-recvfrom]: unable to recvfrom [0]: The operation completed successfully. in C:\xampp\htdocs \socket\client1 .php on line 17

    my server.php as follows...
    <?php
    $address='192.1 68.1.18';
    $port=9000;
    $sock = socket_create(A F_INET, SOCK_DGRAM, SOL_UDP);
    $opt_ret = socket_set_opti on($sock, SOL_SOCKET, SO_BROADCAST, TRUE);
    for($i=1;$i<=90 ;$i++){
    echo $i;
    $send_ret = socket_sendto($ sock, $i, strlen($i), 0, $address, $port);
    if($i==90){
    $i=0;
    }
    sleep(1);
    continue;
    }
    socket_close($s ock);
    ?>

    my client.php as follows...
    <?php
    echo $_SERVER['HTTP_X_FORWARD ED_FOR']."<br>";
    $address = '192.168.1.18';
    $port = 9000;
    $socket = socket_create(A F_INET, SOCK_DGRAM, SOL_UDP);
    socket_bind($so cket, $address, $port);
    socket_recvfrom ($socket, $buf, 12, 0, $address, $port);
    echo $buf;
    ?>

    Please any one help me........
    Thanks in Advance
Working...