function name: socket_recvfrom ()
သက်ဆိုင်သောဗားရှင်း - PHP 4> = 4.1.0, PHP 5, PHP 7
function ကိုဖော်ပြချက် - socket_recvfrom () function ကိုသတ်မှတ်ထားသော socket မှအချက်အလက်များကိုလက်ခံရရှိပြီးသတ်မှတ်ထားသော variable တွင်ပေးပို့သူ၏လိပ်စာနှင့် port ကိုသိုလှောင်ထားသည်။
Syntax: int Socket_recvfrom (INS $ Socket, String & Transring & $ buf, int $ len, int $ legs, strings & $ name [, INT & $ n နာ။ )
parameter သည်ဖော်ပြချက်:
ပြန်လာတန်ဖိုး - အောင်မြင်သောအခါလက်ခံရရှိသည့် Bytes အရေအတွက်ကိုပြန်ပို့ပေးပြီးပျက်ကွက်သည့်အခါမှားယွင်းသောအယူမှားပြန်ပို့သည်။
နမူနာကုဒ်:
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($socket === false) { echo "socket_create() failed: " . socket_strerror(socket_last_error()) . "\n"; exit; } $bind = socket_bind($socket, '0.0.0.0', 8888); if ($bind === false) { echo "socket_bind() failed: " . socket_strerror(socket_last_error($socket)) . "\n"; exit; } $buffer = ''; $senderAddress = ''; $senderPort = 0; // 接收数据并获取发送方的地址和端口$bytes = socket_recvfrom($socket, $buffer, 1024, 0, $senderAddress, $senderPort); if ($bytes === false) { echo "socket_recvfrom() failed: " . socket_strerror(socket_last_error($socket)) . "\n"; exit; } echo "Received $bytes bytes from $senderAddress:$senderPort\n"; echo "Data: $buffer\n"; socket_close($socket);
အထက်ပါနမူနာကုဒ်သည် UDP socket ကိုဖန်တီးသည်။ ထို့နောက်ဒေတာများကိုလက်ခံရရှိရန် socket_recvfrom () function ကို အသုံးပြု. အချက်အလက်များကိုသက်ဆိုင်ရာ variable ကိုသုံးပါ။ နောက်ဆုံးတွင်လက်ခံရရှိသည့်အချက်အလက်များ, ပေးပို့သူ၏လိပ်စာနှင့်ဆိပ်ကမ်းကိုထုတ်ယူ။ socket ကိုပိတ်ပါ။
မှတ်ချက် - ဥပမာ ubp socket တွေကိုသုံးတယ်။ TCP Sockets ကိုသုံးရန်လိုအပ်ပါကဒေတာကိုလက်ခံရရှိရန် Socket_recv () function ကိုသုံးရန်လိုအပ်သည်။