[英]php socket server works only on localhost but not live server
I have hosting domain godaddy and i enabled socket module, but dose not work this code works only in localhost when i upload it in server it does not work. 我有托管域godaddy并启用了套接字模块,但是无法正常工作,当我在服务器中上载它时,此代码仅在localhost中有效。
code server.php 代码server.php
<?php
// set some variables
$host = '150.113.178.20';
$port = 5000;
if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
echo "Socket created \n";
// Bind the source address
if( !socket_bind($sock, $host , $port) )
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not bind socket : [$errorcode] $errormsg \n");
}
echo "Socket bind OK \n";
if(!socket_listen ($sock , 10))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not listen on socket : [$errorcode] $errormsg \n");
}
echo "Socket listen OK \n";
echo "Waiting for incoming connections... \n";
//start loop to listen for incoming connections
while (true)
{
//Accept incoming connection - This is a blocking call
$client = socket_accept($sock);
//display information about the client who is connected
if(socket_getpeername($client , $address , $port))
{
echo "Client $address : $port is now connected to us. \n";
}
//read data from the incoming socket
$input = socket_read($client, 1024000);
$response = "OK .. $input";
// Display output back to client
socket_write($client, $response);
}
when i execute server.php script in ssh no problem 当我在ssh中执行server.php脚本时没问题
but when i write from CMD : 但是当我从CMD写信时:
Error log file 错误日志文件
After some research i found that The code is correct Godaddy does not open custom ports. 经过一番研究,我发现该代码是正确的Godaddy不会打开自定义端口。 The code does not work because have a different security policy localhost than GoDaddy (or other hosting website). 该代码不起作用,因为其安全策略本地主机与GoDaddy(或其他托管网站)不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.