[PHP] What is wrong with this code?

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by XUnreal, Jan 3, 2006.

  1. XUnreal

    XUnreal New Member

    Messages:
    370
    Likes Received:
    0
    Trophy Points:
    0
    I have had a problem trying to make a PHP Socket. The code is below:
    PHP:
    <?php
    error_reporting
    (E_ALL);

    /* Allow the script to hang around waiting for connections. */
    set_time_limit(0);

    /* Turn on implicit output flushing so we see what we're getting
     * as it comes in. */
    ob_implicit_flush();

    $address '{REMOVED}';
    $port 551;

    if ((
    $sock socket_create(AF_INETSOCK_STREAMSOL_TCP)) < 0) {
       echo 
    "socket_create() failed: reason: " socket_strerror($sock) . "\n";
    }

    if ((
    $ret socket_bind($sock$address$port)) < 0) {
       echo 
    "socket_bind() failed: reason: " socket_strerror($ret) . "\n";
    }

    if ((
    $ret socket_listen($sock5)) < 0) {
       echo 
    "socket_listen() failed: reason: " socket_strerror($ret) . "\n";
    }

    do {
       if ((
    $msgsock socket_accept($sock)) < 0) {
           echo 
    "socket_accept() failed: reason: " socket_strerror($msgsock) . "\n";
           break;
       }
       do {
         
    explode(" "$buf)
         if (
    $buf[0] == "LVER") {
           
    $lver "0.1"
           
    if ($buf[1] < $lver) {
             
    socket_write($msgsock"OLD""3");
           }
           if (
    $buf[1] > $lver) {
             
    socket_write($msgsock"NEW""3");
           }
           if (
    $buf[1] == $lver) {
             
    socket_write($msgsock"NEW""3");
           }
           }
         }
           if (
    false === ($buf socket_read($msgsock"550"PHP_NORMAL_READ))) {
               echo 
    "socket_read() failed: reason: " socket_strerror($ret) . "\n";
               break 
    2;
           }
           if (!
    $buf trim($buf)) {
               continue;
           }
           if (
    $buf == 'quit') {
               break;
           }
           if (
    $password == '{REMOVED}') {
               
    socket_close($msgsock);
               break 
    2;
           }
       } while (
    true);
       
    socket_close($msgsock);
    } while (
    true);

    socket_close($sock);
    ?>
    NedreN would probably know the answer but if anyone else knows PLEASE reply.

    Thanks in advance,
    - dphiance.

    NOTE: Sorry about that other post, I accidently pressed Tab then Enter before I finished the post... Please delete the old post.
     
    Last edited: Jan 3, 2006
  2. Corey

    Corey I Break Things Staff Member

    Messages:
    34,552
    Likes Received:
    182
    Trophy Points:
    63
    Are you getting an error, or ? Any other information ? :)

    -Corey
     
  3. Cynical

    Cynical Active Member

    Messages:
    3,492
    Likes Received:
    0
    Trophy Points:
    36
    I get this error:
    You are missing a ; on line 32 and 35. Then I get this error:
    ... which I don't know how to fix.

    EDIT: 200th post! *lame*
     
    Last edited: Jan 3, 2006
  4. XUnreal

    XUnreal New Member

    Messages:
    370
    Likes Received:
    0
    Trophy Points:
    0
    Doesnt matter, fixed it but I get this now:
    Warning: socket_bind() unable to bind address [98]: Address already in use in /home/xunreal/public_html/socket.php on line 19

    Auvee said it was fine to use Sockets, but I either get that error or "Access Denied".

    Corey, Please help :(

    Thanks in advance,
    - dark0r.
     
  5. Corey

    Corey I Break Things Staff Member

    Messages:
    34,552
    Likes Received:
    182
    Trophy Points:
    63
    I'm not really familiar with the permissions on that, see if you can find something online regarding it. I don't have time at the moment to look it up :)

    -Corey
     
  6. XUnreal

    XUnreal New Member

    Messages:
    370
    Likes Received:
    0
    Trophy Points:
    0
    Ok, thanks Corey. Is Auvee away or something? Hes not on MSN :|
     
  7. Phil

    Phil Retired Staff

    Messages:
    7,344
    Likes Received:
    0
    Trophy Points:
    36
    He's on a leave from x10 for a while I know that.
     
  8. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    100
    Trophy Points:
    48
    I can help you out and attempt to see what is up. I can try in a few minutes, but I cannot promise. It might not be until I get home from school when I get the chance. I'll post back whenever that is.
     
  9. flapietoetoe

    flapietoetoe New Member

    Messages:
    226
    Likes Received:
    0
    Trophy Points:
    0
    N/m i posted an error fix wich has been fixed already...
     
    Last edited: Jan 4, 2006
  10. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    100
    Trophy Points:
    48
    I don't get it? Do you still need help? (Him?) What?
     
  11. XUnreal

    XUnreal New Member

    Messages:
    370
    Likes Received:
    0
    Trophy Points:
    0
    Yes I still need help. I get "Address in use" or "Access Denied"
     
  12. chitwa

    chitwa New Member

    Messages:
    128
    Likes Received:
    0
    Trophy Points:
    0
    All ports below 1024 (not very sure) are usually reserved for system or critical services e.g 25 is for SMTP. 98 could be for another service (will give it to you later am in cyber cafe at the moment) . Use something higher than 1024 for less conflicts. If you get access deneid, use something higher
     
  13. Richard

    Richard Active Member

    Messages:
    2,028
    Likes Received:
    0
    Trophy Points:
    36
    I assume the address you are trying to connect to is outside the server? If so, its probably been blocked by the firewall.

    Also most ports if not all below 1024 require root access on a linux server.
     
  14. XUnreal

    XUnreal New Member

    Messages:
    370
    Likes Received:
    0
    Trophy Points:
    0
    its not even been connected to it sends the error when you start the script. I have also tried "4567" and that didn't work, including other numerous stuff.
     
  15. SEÑOR

    SEÑOR The Guy Everyone Hates

    Messages:
    4,638
    Likes Received:
    0
    Trophy Points:
    0
    So u get an error on line blah blah......
     
  16. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    100
    Trophy Points:
    48
    I'm looking at it now, I'll see what I can come up with. Give me a few minutes.
     
  17. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    100
    Trophy Points:
    48
    XUnreal, I fixed the errors but am now stuck. I don't have "something" to test this on, and I don't know what I should. You removed the IP, so socket_bind() doesn't have an address to bind the socket with. I looked up what the port is used for, and that confused me.


    cybercash 551/tcp cybercash
    cybercash 551/udp cybercash

    If you would, will you PM me the IP address so I can test this for you futher and see if I can find out what is up with it?


    Edit: Nevermind actually.. I get the error with whatever I use.

    Edit 2: The only thing I can think of is the address you are attempting to establish a connection to is not "accepting" them on the port you specify/at all.

    Are you trying to do something with like the example(s) on here?

    I'm really unsure of what the "Warning: socket_bind()" error is caused by.
     
    Last edited: Jan 11, 2006

Share This Page