简体   繁体   中英

Transport endpoint not connected, fails on connect()

First, I used bind() and listen() to bind a port to address 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. This is well and good. The listen() function, however, configures the socket as one that will accept connections. If you intend to use the socket to initiate a connection to a remote machine, then you should not use listen() on it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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