socket connect() vs bind()

后端 未结 6 789
臣服心动
臣服心动 2020-12-02 03:35

Both connect() and bind() system calls \'associate\' the socket file descriptor to an address (typically an ip/port combination). Their prototypes

6条回答
  •  借酒劲吻你
    2020-12-02 04:09

    bind tells the running process to claim a port. i.e, it should bind itself to port 80 and listen for incomming requests. with bind, your process becomes a server. when you use connect, you tell your process to connect to a port that is ALREADY in use. your process becomes a client. the difference is important: bind wants a port that is not in use (so that it can claim it and become a server), and connect wants a port that is already in use (so it can connect to it and talk to the server)

提交回复
热议问题