Hi!
SOCKET
Can anyone show me the code of
server in C , windows
and client in PHP using socket
I have managed to do socket from php to php
(both server and client in php)
I need only the simple option for one connection
Here is the code that worked for me in php:
BUT I dont know how to replace the server to be in C windows
(I know the concept. I dont know to write the exact code that will work)
SOCKET
Can anyone show me the code of
server in C , windows
and client in PHP using socket
I have managed to do socket from php to php
(both server and client in php)
I need only the simple option for one connection
Here is the code that worked for me in php:
Code:
simple_server.php
<?php
echo "SERVER start <br/>" ;
$server_socket = stream_socket_server("tcp://84.109.216.123:80");
if ($server_socket ) {
echo "server: OPENED------- <br/>" ;
}
else {
echo "server: FAILED to open OPENED------- <br/>" ;
}
if ($server_socket ) {
$counter = 0;
while ($socket = stream_socket_accept($server_socket)) {
$counter++ ;
printf ( "server: got a new request. conn num:'%d' <br/>", $counter);
$my_msg = sprintf ( "Hello World number '%d' <br> ", $counter ) ;
printf ( " server: my_msg: '%s' <br/>" , $my_msg ) ;
fwrite($socket, $my_msg );
fclose($socket);
}
fclose($server_socket);
}
?>
// simple_client.php
// ----------------------------------
<?php
echo "CLIENT start <br/>" ;
$socket = stream_socket_client('tcp://84.109.216.196:80');
printf ( "client: after stream_socket_client <br /> " );
if(!$socket){
echo "<br>CLIENT: error FAILED to open <br>";
}
else {
echo "<br>CLIENT: opened. good <br>";
while (!feof($socket)) {
$server_msg = fread($socket, 100);
}
fclose($socket);
}
?>
(I know the concept. I dont know to write the exact code that will work)