Under OS-X, I've got process named 'listener' that is waiting on 'accept' to read data from local unix socket named listener_socket. unfortunately, any attempt to connect that socket terminate in 'connection refused' error.
Using lsof, to make sure that the 'listener' actually listen to this socket :
sudo lsof -p 570
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
...
listener 570 root 3u unix 0x48a2751a1bad61ef 0t0 /private/var/run/my_sockets/listener_socket
Notice that the file is, in fact, a valid unix socket :
file /private/var/run/my_sockets/listener_socket /private/var/run/my_sockets/listener_socket: socket
However, it still fail to connect, even when i'm using an alternative way from command like (using socat command)
sudo socat LOCAL:/private/var/run/my_sockets/listener_socket,interval=1 EXEC:'aaaaaaaaaaaaaaaaa',nofork
2015/11/23 00:57:33 socat[928] E connect(3, LEN=49 AF=1 "/private/var/run/my_sockets/listener_socket", 49): Connection refused
perhaps there are more i can do to figure out why i cannot send data to the socket, even-though it's obvious that 'listener' waiting for this data on the other side ?
here's the relevant part of my code :
sender:
sockfd = socket(PF_UNIX, SOCK_STREAM, 0);
address.sun_family = AF_UNIX;
snprintf(address.sun_path, UNIX_PATH_MAX, "%s", LISTENER_SOCKET_PATH);
connect(sockfd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)
write ...
receiver:
fd = socket(PF_UNIX, SOCK_STREAM, 0);
unlink(sock_name); // in case the socket is used before
listen(server->fd, 5); // we don't reach 5 listeners for sure ...
chmod(sock_name, mode); // giving root privilages
accept(server->fd, (struct sockaddr *) &server->address, &server->address_length);
read ...
thanks
A Unix domain socket aka UDS or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing on the same host operating system. It is also referred to by its address family AF_UNIX .
The traditional UNIX system calls are blocking. For example: accept() blocks the caller until a connection is present. If no messages space is available at the socket to hold the message to be transmitted, then send() normally blocks.
Show activity on this post. When the host is "localhost", MySQL Unix clients use a Unix socket, AKA Unix Domain Socket, rather than a TCP/IP socket for the connection, thus the TCP port doesn't matter.
Valid socket types in the UNIX domain are: SOCK_STREAM, for a stream-oriented socket; SOCK_DGRAM, for a datagram-oriented socket that preserves message boundaries (as on most UNIX implementations, UNIX domain datagram sockets are always reliable and don't reorder datagrams); and (since Linux 2.6.
The server seems to miss calling bind()
on the listening socket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With