Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: socket_read()

  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Location
    Cedar Lake, IN
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post socket_read()

    Im trying to read input from an open port using socket_read(). Its actually the exact demo script in the manual (changed to my IP address). Um, The problem im having is that its only reading one letter at a time and not reading returns or spaces. Im thinking it may have something to do with IIS or just the fact that im on a windows machine. Can someone give me a pointer or two?

    -Scott

    This is the code:

    PHP Code:
    <?php 
    error_reporting 
    (E_ALL); 

    set_time_limit (0); 
    ob_implicit_flush (); 

    $address '10.0.0.198'
    $port 23

    if ((
    $sock socket_create (AF_INETSOCK_STREAM0)) < 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; 

    /* Send instructions. */ 
    $msg "\r\nWelcome to PHP telnet server. \r\n" 
    "To quit, type 'quit'. To shut down the server type 'shutdown'.\r\n"
    socket_write($msgsock$msgstrlen($msg)); 
    do { 
    if (
    FALSE === ($buf socket_read ($msgsock2048PHP_NORMAL_READ))) { // added PHP_NORMAL_READ 
    echo "socket_read() failed: reason: " socket_strerror ($ret) . "\r\n"
    break 
    2

    if (!
    $buf trim ($buf)) { 
    continue; 

    if (
    $buf == 'quit') { 
    break; 

    if (
    $buf == 'shutdown') { 
    socket_close ($msgsock); 
    break 
    2

    $talkback "$buf"
    socket_write ($msgsock$talkbackstrlen ($talkback)); 
    echo 
    "$buf\r\n"
    } while (
    true); 
    socket_close ($msgsock); 
    } while (
    true); 

    socket_close ($sock); 
    ?>
    I think its right anyway.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    how are you talking to the server ... via telnet or another script ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New to the CF scene
    Join Date
    Jul 2002
    Location
    Cedar Lake, IN
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well the script is basically a loop-back script only talking to itself. so if i called the script the server and the script the client, the script would be talking to itself via TCP direct on port 23. I actually developed a workaround for my problem by just looping through the keys and add them into an array. when a \r or \n is found it just takes that array, trims it, and sets it against the commands i want. um, Im still very interested if anyone knows the answer to my first question.
    I think its right anyway.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •