刚学网络编程,用udp,请问绑定端口bind()函数应放在发送端还是接收端呢?
我在书上看到是绑定在服务器端,可是我看到有的程序他绑在接收端啊,
???????????????????????

解决方案 »

  1.   

    when you want to determin the specific ip and port, you should use the function bind. otherwise, not.
      

  2.   

    其实都需要绑定,只是在接收端必须绑定到一个固定的端口,便于发送端指明发送的目的地。而发送端即可以调用bind绑定到一个固定端口,也可以由系统分配一个随机的端口用于发送
      

  3.   

    udp的接收端要bind一个端口(事实上不bind port是不行的),发送端则是不用
    udp需要bind,否则怎么固定端口号。
    "It is used to bind to either connection-oriented (stream) or connectionless (datagram) sockets. " -- MSDN