Why bind a socket to an address?

后端 未结 1 1023
一个人的身影
一个人的身影 2020-12-16 14:07

Before \'listen\'ing on a socket I must first bind it to an address. Why? It seems to me that I shouldn\'t have to pick and should just listen to that port on all addresse

相关标签:
1条回答
  • 2020-12-16 14:10

    Binding to an address defines exactly which interface should have that server port open. binding to 0.0.0.0 is a special case when you want to listen to all IP addresses know to the interface. Binding specifically to 127.0.0.1 should make the server port visible only to code that can connect to the localhost (e.g. local processes).

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