lackita has asked for the wisdom of the Perl Monks concerning the following question:
Hey monks, I'm using IO::Socket::INET to listen for incoming data, and I want to be able to close this port within my script. After I start up the socket I connect to the port using telnet, but when either the $socket->close() or $socket->shutdown(2) command is tried my telnet session isn't terminated. Could somebody explain how I can definitively close the port I'm using?
Re: Closing Sockets with IO::Socket::INET
by Perlbotics (Archbishop) on Aug 05, 2008 at 20:10 UTC
|
Lacking some snipped, I just guess.... After accepting a new connection, your program owns two sockets (and handles to those). One socket still listening for new connections and another one that represents the newly established connection (your telnet session). Maybe you just closed the listening socket instead of that of the new connection by confusing the handles? | [reply] [Watch: Dir/Any] |
|
That's a good call, the problem was I wasn't closing the filehandle created by accept. Thanks guys.
| [reply] [Watch: Dir/Any] |
Re: Closing Sockets with IO::Socket::INET
by pc88mxer (Vicar) on Aug 05, 2008 at 16:05 UTC
|
Are you forking to handle the connection? Is it possible that you have the socket opened twice (once in the parent and once in the child)? That would explain why closing the child socket doesn't close the connection.
For an example of how to write a forking TCP server, have a look at the documentation for Net::TCP::Server.
| [reply] [Watch: Dir/Any] |
Re: Closing Sockets with IO::Socket::INET
by Illuminatus (Curate) on Aug 05, 2008 at 16:31 UTC
|
You are going to have to provide more information in order to properly diagnose the problem. You say "I'm using IO::Socket::INET to listen for incoming data, and I want to be able to close this port within my script." You do know that this socket cannot be used to initiate a connection. This socket is designed to take inbound requests from other applications. I think you need to provide a code snippet that better typifies your action. | [reply] [Watch: Dir/Any] |
|