Link to home
Start Free TrialLog in
Avatar of ksprabha_p
ksprabha_pFlag for India

asked on

How to create and run server socket on Hosting Server

Hi,

I own a web server Windows NT based and it supports both .NET, PHP and socket support too.

I have sample server socket code and tested in linux it working fine but i run the code in terminal mode in linux ==> ./serversocket.php.

I want to know how to run the same php file in hosting server.
serversocket.php
 
<?
$host = "xxx.xx.xx.xxx";
$port = 6556;
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
while (true)
{
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
$input = socket_read($spawn, 1024) or die("Could not read input\n");
$input = trim($input);
$output = strrev($input) . "\n";
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
socket_close($spawn);
}
socket_close($socket);
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Xyptilon2
Xyptilon2
Flag of China image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial