Loading ...
Sorry, an error occurred while loading the content.

53IO::Socket:INET Client problem

Expand Messages
  • diarmuid_obriain <diarmuid_obriain@3com.
    Dec 23, 2002
    • 0 Attachment
      I have a problem with a TCP Client I am working with. It works fine
      if the data on the server that is being sent to the socket has
      a '\r\n' at the end of the line however if it does not then that line
      is not printed until after the next \r\n action. This basically makes
      it impossible for the client to see a command prompt from the server
      which would naturally not have the \r\n at the end of the line. Is
      there any way in Perl of forcing the client to print the contents of
      the buffer without waiting for the \r\n sequence.

      Here is the client I am working with.


      Any help appreciated.

      Diarmuid

      ---------------------- tcpClient.pl -------------------------

      #!/usr/bin/perl -w

      use strict;
      use IO::Socket;
      my ($program, $server, $port, $forkchild, $socket, $element);

      if ($0 =~ /.*\/(\S+?)$/){
      $program = $1;
      }else{
      $program = $0;
      }

      unless (@ARGV == 2){
      die "\r\nusage: $0 <host> <port>\r\n\r\n";
      }else{
      ($server, $port) = @ARGV;
      }

      $socket = IO::Socket::INET->new(Proto => 'tcp',
      PeerAddr => $server,
      PeerPort => $port)
      or die "cannot connect : $|";

      print "\r\n[Connected to $server:$port]\r\n";

      print "\r\nFork failed: $!\r\n\r\n" unless (defined ($forkchild = fork
      ()));

      if ($forkchild){
      while ($element = <$socket>) {
      print STDOUT "$element";
      }
      kill("TERM", $forkchild);

      }else{
      while ($element = <STDIN>) {
      print $socket "$element";
      }
      }

      ---------------------------------------------------------------------
    • Show all 4 messages in this topic