2014-09-27 78 views
0

我是使用PHP Websocket的新手。 这是我的问题:如何将数据发送到特定的套接字

我已经成功运行PHP websocket并创建一个简单的聊天应用程序(当然是Web应用程序)。在接收客户数据。所有的客户都会收到这些数据。我怎么能发送数据到指定的客户端,或者可能发送给几个客户端(不是所有的客户端)。

我了解它在here

回答

0
<?php 
    // Create a new socket 
    $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 

    // An example list of IP addresses owned by the computer 
    $sourceips['kevin'] = '127.0.0.1'; 
    $sourceips['madcoder'] = '127.0.0.2'; 

    // Bind the source address 
    socket_bind($sock, $sourceips['madcoder']); 

    // Connect to destination address 
    socket_connect($sock, '127.0.0.1', 80); 

    // Write 
    $request = 'GET/HTTP/1.1' . "\r\n" . 
     'Host: example.com' . "\r\n\r\n"; 
    socket_write($sock, $request); 

    // Close 
    socket_close($sock); 

?> 

来源:http://php.net/manual/en/function.socket-bind.php

相关问题