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
https://forums.phpfreaks.com/topic/71526-sockets/
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
https://forums.phpfreaks.com/topic/71526-sockets/#findComment-360686
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.