简体   繁体   中英

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';
$dest_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.

socket_sento的反面是socket_recvfrom

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM