varspool / Wrench

A simple PHP WebSocket implementation for PHP 7.1
Do What The F*ck You Want To Public License
596 stars 210 forks source link

send message from another PHP script #2

Closed it-can closed 13 years ago

it-can commented 13 years ago

Hi Nico,

thanks for your websocket tool. I use the Echo application. I want to create a php file that connect to this application and I want it to send a message... I have the following script but I can't get it to work...

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$msg = 'hi';
$len = strlen($msg);
socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 8000);
socket_close($sock);
?>```

Can you help me?
nicokaiser commented 13 years ago

Hi!

Well, you cannot just open a socket and then send a message, as the server expects a WebSocket connection, which has a special handshake and message framing (this is what the server is all about). I'm not sure if there is a PHP WebSocket client, this would not make too much sense...

For your usecase, you don't need a WebSocket server but a simple TCP server I think..

Nico

Am 01.09.2011 um 15:47 schrieb MVUG:

Hi Nico,

thanks for your websocket tool. I use the Echo application. I want to create a php file that connect to this application and I want it to send a message... I have the following script but I can't get it to work...

<?php
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

   $msg = 'hi';
   $len = strlen($msg);

   socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 8000);
   socket_close($sock);
?>

Can you help me?

Reply to this email directly or view it on GitHub: https://github.com/nicokaiser/php-websocket/issues/2