I read the documentation, but it is not clear whats the difference between bind() and connect() methods.
I read the documentation , but it is not clear whats the difference between
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
bind()causes the socket to listen for incoming requests on a particular interface/port. In other words, it’s used by servers to respond to incoming requests. Only one socket can bind a port.connect()causes the socket to make a connection to an address/port serviced by a different socket. In other words, it’s used by clients to connect to a server. Multiple clients can connect to a port. NOTE: connect() is not required for use with UDP (datagram) sockets, only TCP/IP. UDP is a broadcast protocol, and connect() does not even require that a socket is listening to the other end.Something like this (adapted from the docs and untested) should send and receive the message “Hello, turnip!” to itself on port 12345: