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

Hi Fellow Monks, I have coded script to connect to my messaging server to retrieve user info by telnet using Socket connection. I think is not IO::Socket is Socket. The problem occur when i telnet to the server, I have issue few command to capture all the infomation I needed. Each command retrieve some detail i needed and store it to the array. Problem is after few command have been issue, in the middle of the process some other command is failed to proceed and no response from the server. The log file I wrote did not give any detail error response. Finally the web browser page time out with error page display. May I know how can I detect whether the error is coz by the telnet session timeout, how to write the detection script and include to my script? Or is there any problem might happen, where server automatically will timeout me in certain of time. But by in cmd prompt, i use telnet command, it seem to be taken very long time the session of telnet only time out. Thank you, urs helps are very appreciate. Kenny

Replies are listed 'Best First'.
Re: Socket connection problem
by Necos (Friar) on Apr 30, 2002 at 12:14 UTC
    You have two possible solutions here (at the very least):

    1.) Net::Telnet (which can be found here)
    Or
    2.) Using IO::Socket to build a socket connection and do the socket data-negotiation manually.

    Personally, I'd opt for the first solution, since Net::Telnet has been around for a while. In addition to Net::Telnet, you might also consider Net::SSH if you have the ability to do so.

    IO::Socket is good to use if you need to define what type of data needs to be passed back and forth (for example, RPC). If you just want to telnet to a box, run a few commands, capture output, and print it to file, you are shooting yourself in the foot (9 times out of 10) by not using Net::Telnet.

    Theodore Charles III
    Network Administrator
    Los Angeles Senior High
    4650 W. Olympic Blvd.
    Los Angeles, CA 90019
    323-937-3210 ext. 224
    email->secon_kun@hotmail.com
    perl -e "map{print++$_}split//,Mdbnr;"