Address already in use… sockets in C

后端 未结 2 690

This question has been asked before, yet I just can\'t seem to come to grips with it as small details of all the questions ive ever seen throw me off...

I keep having is

相关标签:
2条回答
  • 2021-01-26 16:27

    The socket can linger in a TIME_WAIT state for a while after being closed. To be able to reuse a socket while in this state set SO_REUSEADDR

    0 讨论(0)
  • 2021-01-26 16:40

    Yes, the relevant socket option is called SO_REUSEADDR. You use setsockopt() to set socket options.

    You should normally not close the server's main socket though, instead you should use accept() to create per-client sockets, which can be closed when the client disconnects.

    0 讨论(0)
提交回复
热议问题