简体   繁体   English

Linux套接字(AF_UNIX)Connect()失败

[英]Linux Socket (AF_UNIX) Connect() Fail

This part week I have been learning about unix sockets and I have a dount regarding connect() call from the client application. 这部分时间我一直在学习有关unix套接字的知识,并且对从客户端应用程序调用connect()感到迷惑。

Is the connect() function call BLOCKING. 是connect()函数调用BLOCKING。 Will it BLOCK till the server application creates its own socket, binds it to the same address and start listening for incoming connections? 在服务器应用程序创建自己的套接字,将其绑定到相同的地址并开始侦听传入的连接之前,它将阻塞吗?

In my client, what I have is 在我的客户中,我拥有的是

printf(" abc %s\n", bind_path);
if((retval = connect(sh->sock_fd, (const struct sockaddr*)&sadr, sizeof(struct sockaddr_un))) == -1)
{
      perror("123");
      return SOCKET_ERROR;
}
return SOCKET_OK;

And what I get is, 我得到的是

ankit@ankit-ThinkPad-W530:~/Desktop/week2_3_tasks/ipc_socket_exercise$ ./user_application_proc2_client.out 
**** Process 2 (Client) Started
**** Process 2 PID : 7106
/tmp/sock_10 
**** Socket connected successfully with handle 3
 abc /tmp/sock_10
123: No such file or directory
**** Error connnecting socket to address .. exiting

Is the connect() function call BLOCKING[?] connect()函数是否调用BLOCKING [?]

Not for UNIX sockets. 不适用于UNIX套接字。 It may block for other kinds of sockets (such as IP sockets). 它可能阻止其他类型的套接字(例如IP套接字)。

Will it BLOCK till the server application creates its own socket, binds it to the same address and start listening for incoming connections? 在服务器应用程序创建自己的套接字,将其绑定到相同的地址并开始侦听传入的连接之前,它将阻塞吗?

No. You saw this yourself - you got a "no such file or directory" error! 不。您自己看到了-您收到“没有这样的文件或目录”错误! Clearly it didn't wait for a server before it returned that error. 显然,它没有等待服务器返回该错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM