I posted this message, but it never went through:


Not sunny on this end, abit drab today,


I'm workin up a socket bind for a MUD game. Heh, why not, nothin
ta do wright now. I've taken the main socket() call off of php.net
page as an example to bind a port. The script functions, but
when I telnet to the binded port...I get nothing. Any help?

<?php

function init_socket( $port )
{
   /* Allow the script to hang around waiting for connections. */ 
   set_time_limit (0); 

   $address = '216.166.223.178';

  if (($sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
  { 
      echo "socket() failed: reason: " . strerror ($sock) . "\n"; 
  } 

  if (($ret = bind ($sock, $address, $port)) < 0) 
  { 
               echo "bind() failed: reason: " . strerror ($ret) . "\n"; 
  } 

  if (($ret = listen ($sock, 5)) < 0) 
  { 
               echo "listen() failed: reason: " . strerror ($ret) . "\n"; 
  } 

  do 
  { 
                 if (($msgsock = accept_connect($sock)) < 0) 
                 { 
                        echo "accept_connect() failed: reason: " . strerror ($msgsock) 
. "\n"; 
                        break; 
                 }
  
                 do 
                 { 
                                $buf = ''; 
                                $ret = read ($msgsock, $buf, 2048); 
                                if ($ret < 0) { 
                                echo "read() failed: reason: " . strerror ($ret) . 
"\n";
                                break 2; 
                                } 
                                if ($ret == 0) { 
                                break 2; 
                                } 
                                $buf = trim ($buf); 
                                if ($buf == 'quit') { 
                                close ($msgsock); 
                                break 2; 
                                } 
                                $talkback = "PHP: You said '$buf'.\n"; 
                                write ($msgsock, $talkback, strlen ($talkback)); 
                                echo "$buf\n"; 
                                } while (true); 
                                close ($msgsock); 
                                } while (true); 
}

    $port = "6969";
    $control = init_socket( $port );
    printf("Game is up and runnin on %d.", $port );
    close ($control);
    exit( 0 );

?> 
-- 
Kind Regards,
---
Kyndig
Online Text Game Resource Site:  http://www.kyndig.com
ICQ#    10451240
-------------------------------------------------------

-- 
Kind Regards,
---
Kyndig
Online Text Game Resource Site:  http://www.kyndig.com
ICQ#    10451240
-------------------------------------------------------

-- 
Kind Regards,
---
Kyndig
Online Text Game Resource Site:  http://www.kyndig.com
ICQ#    10451240


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to