none
关于绑定套接字到本地的问题 RRS feed

  • 问题

  • 我创建了套接字之后就要用bind函数把套接字绑定到本地地址。。为什么要绑定? 是不是因为我要和别的电脑通信所以要绑定自己然后才可以通信? 还是怎样? 我理解得不够牢固 请哥们帮个忙啦!!谢谢
    法拉利 法拉利 法拉利
    2009年7月30日 14:45

答案

  • MSDN上是这样写的.
    The bind function is used on an unconnected socket before subsequent calls to the connect or listen functions. It is used to bind to either connection-oriented (stream) or connectionless (datagram) sockets. When a socket is created with a call to the socket function, it exists in a namespace (address family), but it has no name assigned to it. Use the bind function to establish the local association of the socket by assigning a local name to an unnamed socket.

    注意最后一句话.若不用bind,你的socket是未命名的,不能通信.


    0xBAADF00D
    2009年7月30日 17:33
    版主

全部回复

  • MSDN上是这样写的.
    The bind function is used on an unconnected socket before subsequent calls to the connect or listen functions. It is used to bind to either connection-oriented (stream) or connectionless (datagram) sockets. When a socket is created with a call to the socket function, it exists in a namespace (address family), but it has no name assigned to it. Use the bind function to establish the local association of the socket by assigning a local name to an unnamed socket.

    注意最后一句话.若不用bind,你的socket是未命名的,不能通信.


    0xBAADF00D
    2009年7月30日 17:33
    版主
  • MSDN上是这样写的.
    The bind function is used on an unconnected socket before subsequent calls to the connect or listen functions. It is used to bind to either connection-oriented (stream) or connectionless (datagram) sockets. When a socket is created with a call to the socket function, it exists in a namespace (address family), but it has no name assigned to it. Use the bind function to establish the local association of the socket by assigning a local name to an unnamed socket.

    注意最后一句话.若不用bind,你的socket是未命名的,不能通信.


    0xBAADF00D

    哥们 我看不懂英文 不过你最后一句话我注意到了 呵呵 谢谢
    法拉利 法拉利 法拉利
    2009年7月31日 0:40
  •        要根据你要怎么用这个socket,如果仅仅是客户端socket,去连接远端server,那就不用bind,直接connect就行了.
          bind只是用在listen之前,不listen的话不用bind.

    just learn
    2009年7月31日 2:40