1. 用getsockname获得。
For TCP/IP, if the port is specified as zero, the service provider assigns a unique port to the application with a value between 1024 and 5000. The application can use getsockname after calling bind to learn the address and the port that has been assigned to it.2. 这好像不行,除非你用setsockopt设置了keepalive选项。

解决方案 »

  1.   

    一、返回的socket就是了。
    二使用
    int select (
      int nfds,                           
      fd_set FAR * readfds,               
      fd_set FAR * writefds,              
      fd_set FAR * exceptfds,             
      const struct timeval FAR * timeout  
    );进行检查
      

  2.   

    to  julienjut(秋水):
    1. 楼主问的是bind时分配的端口号,他已经建立socket了。
    2. select可以处理对方突然死机的情况吗?