LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Converting php5 socket functions to php3 socket functions (http://www.linuxquestions.org/questions/programming-9/converting-php5-socket-functions-to-php3-socket-functions-336405/)

mrobertson 06-23-2005 09:11 AM

Converting php5 socket functions to php3 socket functions
 
I have the following socket functions coded in php5. I need to convert them to php3 which I am assuming is dealing with the fsockopen function. I am new to php coding and was wondering if anyone can help me with this task. Basically I need to go right down the line and get the equivalent function for socket create, socket_bind, socket_listen, socket_accept, socket_read. Can anyone help me with this?

Code:

if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
                echo "socket_create() failed. Reason: " . socket_strerror($sock) . "<BR>";
        }

        if (($ret = socket_bind($sock, $address, $port)) < 0) {
                echo "socket_bind() failed. Reason: " . socket_strerror($ret) . "<BR>";
        }

        //Start listening on the socket
        if (($ret = socket_listen($sock, 5)) < 0) {
                echo "socket_listen() failed. Reason: " . socket_strerror($ret) . "<BR>";
        }

        //Accept an incoming connection
        if(($client = socket_accept($sock)) < 0) {
                echo "socket_accept() failed. Reason: " . socket_strerror($ret) . "<BR>";
                break;
        }

        //Read whatever was just sent, 1024 bytes' worth. Make this however long you need.
        if( false == ($global_string = socket_read($client, 2048))) {
                echo "socket_read() failed. Reason: " . socket_strerror($ret) . "<BR>";
                break;
        }



All times are GMT -5. The time now is 12:37 PM.