Can't connect to local socket, connection refused

左心房为你撑大大i 提交于 2019-12-12 02:56:36

问题


I've been at this for a few days now and just can't crack the problem. I've also put it up on the Ubuntu forum and heard nothing. Basically, I have a local socket in /tmp/mysockets which I create successfully in a php script--

if (($sock = socket_create(AF_UNIX, SOCK_STREAM,0)) === false) 
{
    echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
        exit();
}

but to which I cannot connect, via

if (socket_connect($sock, $sock_str) === false) 
{
        echo "socket_connect() on " . $sock_str . " failed: reason: " . socket_strerror(socket_last_$
        socket_close($sock);
        exit();
}

This gives me

Warning: socket_connect(): unable to connect [111]: Connection refused in /var/www/myscript.php on line 66 socket_connect() on /tmp/mysockets/sock failed: reason: Connection refused

Now, I thought this might be a permissions issue, but I've chmod 777'ed the /tmp, mysockets, and sock, and it doesn't matter. What could be the problem?


回答1:


You need to use socket_bind() and socket_listen() after socket_create().




回答2:


So, it turns out that the process that was supposed to be listening for this socket crashed--I'm doing this remotely (and I'm just getting used to remote compiling/debugging) so I didn't see this at first. Sorry guys I described the problem incorrectly. @duskwuff you had the right idea.



来源:https://stackoverflow.com/questions/7211827/cant-connect-to-local-socket-connection-refused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!