I have a socket that is set up to listen()
Normally I would accept() these connections based on a file descriptor being ready via select(). Can I change this to be a recv() instead of accept(), with that same file descriptor?
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.
No, they’re not interchangeable.
You’re only listening on a single file descriptor using
select, but you want have a file descriptor per connection once you have connected clients.acceptextracts the first connection request on the queue of pending connections for the listening socket, creates a new connected socket, and returns a new file descriptor referring to that socket.Once you have that new file descriptor, you can use recv to receive data from the client on it.