Jump to content

Sockets


glenelkins

Recommended Posts

Hi

 

I have a script called "server.php" . This is just a basic test script for now with the following code:

 

<?php

// Create the socket
$socket = socket_create ( AF_INET, SOCK_STREAM, SOL_TCP);

// Bind the socket to the localhost
socket_bind ( $socket, 'localhost', 1337 );

// Listen for connections
socket_listen ( $socket );

// accept any incoming connection and write to the socket. 
while( $connection = socket_accept( $socket ) ){

// Write welcome message to the socket
socket_write($connection,'You\'ve successfully connected to my computer!\r\n');

} 

?>

 

As you can see it listens for connections on port 1337.  Now the issue is, how do I make this script actually run on the server to listen for connections without manually going through the web browser? For example, i telnet to that port and the script should pick it up

 

thanks

Link to comment
Share on other sites

Yes i figured that one! Thanks

 

though there is an issue. It binds fine to the IP i put in there. But when the telnet is connected through, there is no output when there should be: You've successfully connected to my computer!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.