gpt4 book ai didi

php - PHP套接字不监听

转载 作者:行者123 更新时间:2023-12-03 11:54:17 25 4
gpt4 key购买 nike

include 'config.php';
set_time_limit(0);
//sending message
$msgOkay = "okay";
$msg1 = "1";
$msg2 = "2";
$msg3 = "3";
$msg4 = "4";
$msg5 = "5";
$msg6 = "6";

echo "Starting Listening Master. \n";

$sock = socket_create(AF_INET, SOCK_STREAM, 0);
if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0))){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);

die("Failed to create socket: [$errorcode] $errormsg \n");
}
echo "Socket created! \n";
socket_bind($sock, 0, 899);
echo "Socket Bound \n";
while (true) {

socket_listen($sock, 100);
echo "Listening for connections \n";
$client = socket_accept($sock);
echo "Connection Established. \n";
if(socket_getpeername($client , $address, $port)){
echo "Client $address : $port has successfully established connection with socket master. \n";
}

$input = socket_read($client);
$request = explode("\n", $input);
if($request[0] == "dovote"){
$key = $request[1];
$id = $request[2];
$player = $request[3];
$ip = $request[4];



}

elseif($request[0] == "test"){
$key = $request[1];
$id = $request[2];
$player = $request[3];
$ip = $request[4];

$QueryTest = ("SELECT * FROM socketmanager WHERE privatekey = '".$key."' AND id = '".$id."'");
$resultTest = mysql_query($QueryTest);
if(mysql_num_rows($resultAuth) == "1"){
socket_send($sock, $msg1, strlen($msg1), 0);
}
else{
socket_send($sock, $msg3, strlen($msg3), 0);
}

}

else{
if(!socket_send($sock, $msg3, strnlen($msg3), 0)){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not send data: [$errorcode] $errormsg \n");
}
}



}

我已将此文件上传到我的Web服务器,该服务器是VPS,我可以控制所有内容(端口899已打开)。而在Mac上运行时:
telnet
open ip 80

将其打开并关闭。在网络服务器上,我运行了脚本,除了“监听连接”之外,我什么都看不到。

最佳答案

我认为这与许可问题有关:

Non-root user can't bind port below 1024.
SELinux limitation or firewall problems.

您应该检查socket_bind()和socket_listen()返回TRUE或FALSE,然后对其进行深入调试。

关于php - PHP套接字不监听,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16631920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com