Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am doing a little bit of networking and i am trying to write a script that lets me communicate with servers. I was wondering if it's a good idea to use the module Net::Telnet instaed of working with sockets. If working with sockets directly is the way to go forward is it useful/better to use the built-in socket functions iso using the module IO::Socket::INET, or maybe it is more or less the same? I hope to hear from you, ty.

Replies are listed 'Best First'.
Re: socket programming
by ikegami (Patriarch) on Dec 20, 2025 at 18:24 UTC

    Net::Telnet is used to establish a telnet connection and interacting with the resulting interactive terminal.

    Net::SSH::Expect is the parallel for ssh.

    If that's what you want to do, it makes perfect sense to use one of these. But you didn't mention telnet (or ssh). You simply mentioned establishing a socket connection. These are not appropriate for that.

    For that, you could use the C-style builtin socket functions directly. But I recommend using IO::Socket::INET or IO::Socket::IP instead. They are thin wrappers for the same C functions, but they are easier to use because they aren't limited to what works well in C. Code that uses them is therefore easier to read/maintain/debug/etc than code that uses a C-style interface.

    Specifically, I recommend using IO::Socket::IP because it supports IPv4 and IPv6, whereas IO::Socket::INET only supports IPv4.

Re: socket programming
by talexb (Chancellor) on Dec 20, 2025 at 18:25 UTC

    I would say that it depends on what kind of interface you're dealing with. If you're having just a regular line-based conversation, Net::Telnet would probably be fine. IO::Socket::INET might be more appropriate if it's more character-based.

    Alex / talexb / Toronto

    As of June 2025, Groklaw is back! This site was a really valuable resource in the now ancient fight between SCO and Linux. As it turned out, SCO was all hat and no cattle.Thanks to PJ for all her work, we owe her so much. RIP -- 2003 to 2013.