I need help I have spent countless hours attempting to learn and I am about to pull my hair.
My task that I want to accomplish is: Send a packet to the server and make the server ping back the client. I want to calculate the time it takes to complete the connection.
I have been trying to send a packet form the client to the server. Receive it from the server and send it back to the client.
I have code that I have been trying but it doesn't not work.
Server:
<?php
//Create the socket on the specified port.
$socket = socket_create_listen($port);
//Wait for incoming connections.
$connection = socket_accept($socket);
//Create a socket and connect it to the server.
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, 'localhost', 33335);
//Create a message, and send it to the server on $socket.
$message = "This is a message from the client.\n";
socket_send($socket, $message, strlen($message), MSG_EOF);
//Close the socket.
socket_close($socket);
?>
Client:
<?php
//Create a socket and connect it to the server.
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, 'localhost', 33335);
//Create a message, and send it to the server on $socket.
$message = "This is a message from the client.\n";
socket_send($socket, $message, strlen($message), MSG_EOF);
//Close the socket.
socket_close($socket);
?>