Network programming

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Network programming

    hello guys,

    Have'nt been here for a long time.so, howz everybody doing?

    OK, lets get into the topic.I would like to do some sort of communication between to PC's on Windows-NT environment.I know there should be some sort of service running on the other machine, right???I would like to have a very basic script in-ordet to test that I'm able to connect to sockets and listen or atleast some ideas would be fine.

    I've read in the manual and understood something about sockets and written a small script.WHat does this do??The user inputs some text and submit it, it connects to the other machine(Via IP-address) and it return the string in reverse order.

    what steps should i take, would be really greatful if somebody can drive me in the right direction.

    Thanks!

    PHP-Code:
    <html>
    <head
    </head>

    <body>
    <?php
    //Form not yet submitted
        
    if (!$submit)
        {
    ?>
    <form action="<? echo $PHP_SELF; ?>" method="post">
    Enter some text:<br>
    <input type="Text" name="message" size="15"><input type="submit" name="submit" value="send">
    </form>
    <?
        }
        else{
    //form submitted

    //Where is the socket server?
        $host="IP address of the machine";
        $port = port no;
    //create a socket
        $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die ("could not create socket\n");
    //connect to server
        $result = socket_connect($socket, $host, $port) or die ("could not connect to server\n");

        socket_read ($socket, 1024) or die ("could not read server response\n");
    //send string to server
        socket_write($socket, $message. strlen($message)) or die ("could not send data to server\n");
    //get server response
        socket_read ($socket, 1024) or die ("could not read server response\n");
    //end session
        socket_write($socket, "END", 3) or die ("could not end session\n");
    //close socket
        socket_close($socket);
    //clean up result
        $result = trim($result);
        $result = substr($result, 0, strlen($result)-1);
    //print result to browser
    ?>
        Server said: <b><? echo $result; ?></b>
    <?
        }
    ?>
    </body>
    </html>
    Happiness is a state of mind.
    Change your mind and be happy!
Lädt...
X