Announcement

Collapse
No announcement yet.

Sockets

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gunerman
    replied
    Oh and here is the code I am currently using (adapted from the php manual), also if you know of a more efficent way of doing this please tell me
    PHP Code:
    <?php

    dl
    ('php_sockets.dll');

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

    $address 'xxx.xxx.x.xxx';
    $port 10000;

    $sock socket_create(AF_INETSOCK_STREAM0);

    socket_bind($sock$address$port);

    socket_listen($sock5);

    while (
    true)
    {
        
    $msgsock socket_accept($sock);

        
    $do_again "y";

        while (
    $do_again == "y")
        {
            
    $talkback "\n\rServer: Please input data...\n\r";
            
    socket_write($msgsock$talkbackstrlen ($talkback));
        
            
    $text socket_read($msgsock2);
        
            
    $talkback "\n\rServer: You said '$text'.\n\r";
            
    socket_write($msgsock$talkbackstrlen ($talkback));
            echo 
    "$text\n";

            
    $talkback "\n\rServer: Would you like to do that again ?\n\r";
            
    socket_write($msgsock$talkbackstrlen($talkback));

            
    $choice socket_read($msgsock1);

            
    $choice trim($choice);

            if (
    $choice == "n")
            {
                
    $talkback "\n\rServer: No?...quiting...\n\r";
                
    socket_write($msgsock$talkbackstrlen($talkback));
                break;
            }
            elseif (
    $choice == "y")
            {
            }
            else
            {
                
    $talkback "\n\rServer: Invalid answer...quiting...\n\r";
                
    socket_write($msgsock$talkbackstrlen($talkback));
                break;
            }
        }

        
    socket_close ($msgsock);
    }
    socket_close ($sock);
    ?>

    Leave a comment:


  • Gunerman
    started a topic Sockets

    Sockets

    I need help =( I made a simple TCP/IP server that will talk to someone, but for some reason when typing it will only allow one letter and then stop letting you type. How do I get it so people can type a sentance or more?

    Also, it will only allow one person to talk to it. How do I get it to accept lots of connections? (Like up to 10)?

    And is there a turorial somewhere on PHP sockets?

    Thanks in advance,

    Gunerman
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X