home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / protocol / tcpip / 5084 < prev    next >
Encoding:
Text File  |  1992-11-08  |  1.4 KB  |  41 lines

  1. Newsgroups: comp.protocols.tcp-ip
  2. Path: sparky!uunet!blaze.cs.jhu.edu!beanworld!eifrig
  3. From: eifrig@beanworld.cs.jhu.edu (Jonathan Eifrig)
  4. Subject: Proper Method of Closing IP Sockets
  5. Message-ID: <1992Nov7.034406.19500@blaze.cs.jhu.edu>
  6. Sender: news@blaze.cs.jhu.edu (Usenet news system)
  7. Organization: The Johns Hopkins University CS Department
  8. Date: Sat, 7 Nov 1992 03:44:06 GMT
  9. Lines: 30
  10.  
  11.     What is the proper method of closing a socket in order to release
  12. the socket/port binding?  Under SunOS 4.1, my application closes its
  13. descriptors and exists.  If I immediately execute it again, the bind fails
  14. with errno EADDRINUSE.  Eventually, operating system figures out that
  15. the old process is defunct, but I would like to do this properly.
  16.  
  17.     The server process just does the standard socket/bind/listen/accept
  18. song-and-dance:
  19.  
  20.         sin.sin_family = AF_INET;
  21.         sin.sin_port = htons(PORTNUM);
  22.         sin.sin_addr.S_un.S_adder = INADDR_ANY;
  23.  
  24.         s = socket(AF_INET, SOCK_STREAM, 0);
  25.         bind (s, &sin, sizeof(sin));
  26.         listen(s,5);
  27.         con = accept(s, &fsin, &conlen);
  28.  
  29.         /*  Fool around with the socket. */
  30.  
  31.         close(con);
  32.         close(s);
  33.  
  34.         exit();
  35.  
  36.     What am I missing here?
  37.  
  38. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  39. Jack Eifrig (eifrig@cs.jhu.edu)       The Johns Hopkins University, C.S. Dept.
  40. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  41.