510carlos Posted November 12, 2012 Share Posted November 12, 2012 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/270576-socket-programing/ Share on other sites More sharing options...
PeopleUnderTheStairs Posted November 12, 2012 Share Posted November 12, 2012 (edited) What about it doesn't work? Pretty much useless just saying "it doesn't work" EDIT: You're not accepting connections on the server. Read a bit about socket_* functions and how to create a basic TCP server, it should help you out a lot Edited November 12, 2012 by PeopleUnderTheStairs Quote Link to comment https://forums.phpfreaks.com/topic/270576-socket-programing/#findComment-1391786 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.