Re: How do you close a port immediately?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steffen wrote:
> Hi,
>
>> I'm playing around with sockets at the moment. Currently reading up
>> some online guides and experimenting on my own.
>>
>> After the server is launched, it will be there sitting like a duck
>> until it receives something. Usually if I need to make amendments to
>> the code, i will press ctrl+c to terminate it. After termination , the
>> port 9999 is still active and will be in TIME_WAIT status.
>>
>> Because during this TIME_WAIT period, I can still launch the simple
>> stream server. But netstat shows that port 9999 will still be in
>> TIME_WAIT period instead of LISTEN. The simple stream client will
>> encounter perror of "Connection Refused" during this TIME_WAIT period.
>
>
> you can install a handler for the SIGINT signal that is invoked by
> ctrl+c and shut down your sockets properly.

The OP should also use the SO_REUSEADDR socket() option (in the first
instance of the server) to permit the restarted (second instance) server to
claim the port that's in TIME_WAIT status.

- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFDpsKwagVFX4UWr64RAqPjAKDpZpQ1QWoBQBZ1LIpUb5lbEFb2DgCfSske
chfAKEfjst/ptYweFLraeyk=
=chPS
-----END PGP SIGNATURE-----
.



Relevant Pages

  • Re: network programming: how does s.accept() work?
    ... The program you contact at Google is a server. ... so, the server will usually assign a new port, say 56399, specifically ... connections to a server remain on the same port, ... sockets is what identifies them. ...
    (comp.lang.python)
  • Re: Socket switch delay
    ... hadn't realized the bit about the completion port... ... > can come back with partial buffers from a completion io. ... > in the client and server. ... > remember changing in the server was the "non-blocking sockets" together ...
    (microsoft.public.win32.programmer.networks)
  • Re: Router/Firewall Port Mapping Question
    ... Sockets on the PC can be client or servers. ... The port number is usually selected by the ... and a Server on the other. ...
    (comp.security.firewalls)
  • Re: Sockets: connection refused
    ... data from 3 equipments using sockets. ... Several hours later, when restarting the application, I get a ... check to make sure that the program that listens on that port is ... it might be a resource leak in the server. ...
    (comp.unix.programmer)
  • Re: Banana Republic (was Re: OpenVMS Book Wins award)
    ... client ... No bollocks HTTP, SOAP, XML, Java, Garbage ... receive messages from any number of server processes who in turn could be ... Unlike TCP/IP and/or UDP Sockets with Java that have been around since ...
    (comp.os.vms)