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

I am writing an SMTP client using only the IO::Socket package. I am able to successfully communicate with the server and write to and read from the socket. But at one specific point the socket is being closed and if I don't check to see if the socket is opened I produce the "Broken socket" error. Here is the communication lines between me and the server.
*********************************** Command: EHLO mail.XXXXXXX.com Line (0): 250-167211-www1.XXXXXXX.com Line (1): 250-AUTH=LOGIN CRAM-MD5 PLAIN Line (2): 250-AUTH LOGIN CRAM-MD5 PLAIN Line (3): 250-STARTTLS Line (4): 250-PIPELINING Line (5): 250 8BITMIME Command: AUTH LOGIN Line (0): 334 VXNlc44kDJK4kl Command: bm9yZXBs3920KDSldzLmNvbQ== Line (0): 334 UGF3kl324Q6 Command: MX443kDKSDldZ5 Software error: 'Broken pipe' at..... ***********************************
Right after I write the password to the socket, it gets closed somehow. Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: IO::Socket Broken Pipe
by gone2015 (Deacon) on Jan 30, 2009 at 10:02 UTC

    My guess would be that the far end has taken one look at what you sent and dropped the connection so fast that feet are not in contact with the ground.

    I suppose it's possible that the conversation did not go quickly enough for the far end, and it has timed you out and closed the connecton with similar effect feet-and-ground-wise.

    You could try telnet and see if you get the same effect. Though there I guess the problem will be computing the responses to the challenges and typing them in quickly enough !

      That sounds reasonable. On the assumption that you (complexodus) have control of the test server, try some other operations that don't require authentication, in order to narrow down the problem.

      cat >~/.sig </dev/interesting

Re: IO::Socket Broken Pipe
by targetsmart (Curate) on Jan 30, 2009 at 18:40 UTC
    You can handle the SIGPIPE signal, and attempt a(cleaning and) reconnection, for more information see perlipc man page.

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.