Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Feb 2003
    Posts
    15
    Member #
    609
    Hello everybody,
    I read the Socket Programming TUTORIAL and tried to execute the simple server example.
    When i telnet to the ip-address and port, it connects, and when i input a string, it losts the connection.I first execute this script from the command prompt, it gives me the message "waiting for connections...." and when i telnet to the ip-address and port no, it gives me the message "Received connection request" and now when i try to input a string, it immediately lost the connection.could somebody please tell me why is this happening.
    Thanks in advance.
    Heres the script
    PHP Code:
    <?php

    // set some variables
    $host "Ip-address";
    $port 1234;

    // don't timeout!
    set_time_limit(0);

    // create socket
    $socket socket_create(AF_INETSOCK_STREAM0) or die("Could not create socket\n");

    // bind socket to port
    $result socket_bind($socket$host$port) or die("Could not bind to socket\n");

    // start listening for connections
    $result socket_listen($socket3) or die("Could not set up socket listener\n");
    echo 
    "waiting for connections....\n";
    // accept incoming connections
    // spawn another socket to handle communication
    $spawn socket_accept($socket) or die("Could not accept incoming connection\n");
    echo 
    "Received connection request\n";

    // read client input
    $input socket_read($spawn1024) or die("Could not read input\n");

    // clean up input string
    $input trim($input);

    // reverse client input and send back
    $output strrev($input) . "\n";
    socket_write($spawn$outputstrlen ($output)) or die("Could not write output\n");

    // close sockets
    socket_close($spawn);
    socket_close($socket);
    ?>

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    PHP Code:
    socket_close($spawn);
    socket_close($socket); 
    You're closing the socket after it reads the input string.

  4. #3
    Junior Member
    Join Date
    Feb 2003
    Posts
    15
    Member #
    609
    Hello transio,

    Well, Once the output has been sent back to the client, I'm terminating both the sockets.i.e,
    PHP Code:
    // read client input
    $input socket_read($spawn1024) or die("Could not read input\n");

    // reverse client input and send back
    $output strrev($input) . "\n";
    socket_write($spawn$outputstrlen ($output)) or die("Could not write output\n"); 
    Am i wrong??Is there any other way to get it done working.

    Thanks for your time


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:41 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com