开发者

Read a socket connection in php

After i create a socket connection using socket_create(),socket_bind() and send a message to another port of my machine how to read the message that i have send? for example:

$address = '127.0.0.1';
$port = 4000;
$dest_address = '127.0.0.1';
$de开发者_运维技巧st_port = 4027;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($sock, $address, $port);
$msg = "Ping !";  
socket_sendto($sock, $msg, strlen($msg), 0, $dest_address, $dest_port);
socket_close($sock);

after this do i need to do the following?

$sockread = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($sockread, $address, $dest_port);
socket_listen($sockread);

Sorry if my question is irrelevant, I am new to sockets connections.


The opposite of socket_sento is socket_recvfrom.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜