简体   繁体   English

传输端点未连接,在connect()上失败

[英]Transport endpoint not connected, fails on connect()

First, I used bind() and listen() to bind a port to address 0.0.0.0. 首先,我使用bind()listen()将端口绑定到地址0.0.0.0。 However, now I cannot connect. 但是,现在我无法连接。

sprintf (addrbuf, "%s-%d", SVR_ADDR, SVR_PORT);
StringToSockaddr (addrbuf, &destAddr);
if (connect(psock,(struct sockaddr *) &destAddr,sizeof(destAddr)) < 0)
    die("failed to connect to server");
printf("connected to server at %s\n",getTime());

The bind() function assigns a local address and/or port to the socket. bind()函数将本地地址和/或端口分配给套接字。 This is well and good. 这很好。 The listen() function, however, configures the socket as one that will accept connections. 但是, listen()函数将套接字配置为将接受连接的套接字。 If you intend to use the socket to initiate a connection to a remote machine, then you should not use listen() on it. 如果打算使用套接字来启动与远程计算机的连接,则不应在其上使用listen()

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

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