home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.protocols.tcp-ip
- Path: sparky!uunet!blaze.cs.jhu.edu!beanworld!eifrig
- From: eifrig@beanworld.cs.jhu.edu (Jonathan Eifrig)
- Subject: Proper Method of Closing IP Sockets
- Message-ID: <1992Nov7.034406.19500@blaze.cs.jhu.edu>
- Sender: news@blaze.cs.jhu.edu (Usenet news system)
- Organization: The Johns Hopkins University CS Department
- Date: Sat, 7 Nov 1992 03:44:06 GMT
- Lines: 30
-
- What is the proper method of closing a socket in order to release
- the socket/port binding? Under SunOS 4.1, my application closes its
- descriptors and exists. If I immediately execute it again, the bind fails
- with errno EADDRINUSE. Eventually, operating system figures out that
- the old process is defunct, but I would like to do this properly.
-
- The server process just does the standard socket/bind/listen/accept
- song-and-dance:
-
- sin.sin_family = AF_INET;
- sin.sin_port = htons(PORTNUM);
- sin.sin_addr.S_un.S_adder = INADDR_ANY;
-
- s = socket(AF_INET, SOCK_STREAM, 0);
- bind (s, &sin, sizeof(sin));
- listen(s,5);
- con = accept(s, &fsin, &conlen);
-
- /* Fool around with the socket. */
-
- close(con);
- close(s);
-
- exit();
-
- What am I missing here?
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Jack Eifrig (eifrig@cs.jhu.edu) The Johns Hopkins University, C.S. Dept.
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-