Hello Stefan,

> Ok, I replied to the previous response to my post and it apparently didn't
> go through, but it's irrelevant anyway.  (My response to the "why bother"
> was summed up with "so I can learn how it's done.")
>

good point, although why not build the socket your self [ you can even pack
raw sockets if you wish ]??


> When I do the sockets this way, it waits for input on the $dccsocket
> without
> moving on to work on the information from the $socket until I send a /dcc
> close
> chat $mybotsnick... After I close the DCC CHAT connection, it reads from
> the $socket again without problem...  I've change this recently to:
>
in the snipet you send there is no code to handle "/dcc close" . The
behavior you explained fallows as your code. I think the only reason you are
geting past the read , is because $dccsocket points to a non valid handle.
If you have warnings enabled you should get a message.

 >With the
> $socket->blocking(0) and the sysread() calls, I should be able
> to read without problems from either one, but now it fails to even open
the
> $dccsocket.

ok before I answare that, dont mix blocking IO with NON_blocking IO[ print
on socket, stdio and all high level io functions use there own buffering
scheme ] atleast $|=1 on top of your script should disable stdlib buffering,
I woudl avoid print and <> in general for NON-BLOCKING IO.

> print $socket "PRIVMSG $channel $dcctmp\r";
 are you sure all data got send over this socket ?? maybe the server has
closed your socket by now ?? or maybe it couldnt handle the whole message ??
If I was you I would select() to make sure socket is ready for read. check
sysread if it return anything  or $! might be EWOULDBLOCK.

$data="PRIVMSG $channel $dcctmp\r";
$status=sysread($socket,$data,$max_buff);
if( defined $status){
    if($status >0){print "full read of $status bytes on socket" if
$debug); }
    else{ print "recieved EOF on socket\n" if $debug; }
}
elsif($! == EWOULDBLOCK){warn "socket no read to be read yet\r\r";#handle
how you wish }
else{ warn "error on socket: $!"; }



> bypass the router and neither one works.  The second may be due to
> the way XChat opens it's socket.  If it bound it to listen on a
> specific IP then it may not be listening to localhost and I wouldn't be
> able to connect, but the only IP it should listen on
> if that's the case is my '192.168.x.x' IP from my router.  I
> tried setting to that IP as well with no luck

could be, if you want send me your IP and i'll give it a run.

Mark

----- Original Message -----
From: "Stefan Johnson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: "Mark G" <[EMAIL PROTECTED]>
Sent: Monday, March 24, 2003 12:32 PM
Subject: Re: Socket Problem


> On Sun, 23 Mar 2003 22:43:16 -0500, Mark G <[EMAIL PROTECTED]> wrote:
>
> > Hi Stefan,
> >
> > If you have two different sockets open, one should not block the other
no
> > meter what kind of a socket that is. Send some of the code, might help
us
> > help you.
> >
> > Mark
>
> Ok, I replied to the previous response to my post and it apparently didn't
> go through, but it's irrelevant anyway.  (My response to the "why bother"
> was summed up with "so I can learn how it's done.")
>
> I added that for the benefit of the list. :)
>
> Now... the following is a snippet of the relevant code (before I changed
> it to use non-blocking IO.)
>
> ------------- Cut Below ------------------
>
> #!/usr/bin/perl
>
> $server = 'localhost';
> $port = 6667;
>
> $channel = '#mychannel';
>
> $a = (special character for dcc, actions, etc...)
>
> $dccexists = 0;
> $dcctmp = "";
>
> $socket = IO::Socket::INET->new(
>    Proto => 'tcp',
>    PeerAddr => $server,
>    PeerPort => $port
> );
>
> unless( $socket ) {
>    die( "Could not connect to $server:$port" );
> }
>
> $socket->autoflush(1);
>
> while ( $tmp = <$socket> ) {
>    if { $tmp ne "" ) {
>       if ( $dccexists == 1 ) {
>          $dcctmp = <$dccsocket>;
>       }
>       if ( $dcctmp ne "" ) {
>          print "PRIVMSG $channel $dcctmp\n";
>          print $socket "PRIVMSG $channel $dcctmp\r";
>          $dcctmp = "";
>       }
>       @tmps = split( /:/, $tmp );
>       $command = $tmps[2];
>       @tmps = split( ' ', $tmp );
>       if ( $command =~ /DCC CHAT/i ) {
>          $command =~ s/$a//g;
>          $dccport = $tmps[$#tmps];
>          $dccip = $tmps[$#tmps-1];
>          $dccsocket = IO::Socket::INET->new(
>             Proto => 'tcp',
>             PeerAddr => $dccip,
>             PeerPort => $dccport
>          );
>          if ( $dccsocket ) {
>             $dccexists = 1;
>             $dccsocket->autoflush(1);
>             print "DCC CHAT\n";
>             print $dccsocket "DCC CHAT\r";
>             print "PRIVMSG $controller :Ready and waiting!\n";
>             print $socket "PRIVMSG $controller :Ready and waiting!\r";
>          } else {
>             print "UNABLE TO ESTABLISH DCC CONNECTION TO $dccip
> $dccport\n";
>             $dccexists = 0;
>          }
>       }
>    }
> }
>
> ------------ End Cut Area ------------
>
> When I do the sockets this way, it waits for input on the $dccsocket
> without
> moving on to work on the information from the $socket until I send a /dcc
> close
> chat $mybotsnick... After I close the DCC CHAT connection, it reads from
> the $socket again without problem...  I've change this recently to:
>
> ---------------- Cut Code Here -----------------
>
> #!/usr/bin/perl
>
> $server = 'localhost';
> $port = 6667;
>
> $channel = '#mychannel';
>
> $a = (special character for dcc, actions, etc...)
>
> $dccexists = 0;
> $dcctmp = "";
>
> $done = 0;
>
> $socket = IO::Socket::INET->new(
>    Proto => 'tcp',
>    PeerAddr => $server,
>    PeerPort => $port
> );
>
> unless( $socket ) {
>    die( "Could not connect to $server:$port" );
> }
>
> $socket->blocking(0);
> $socket->autoflush(1);
>
> while ( !$done ) {
>    $tmp = "";
>    @tmps = "";
>    $msglen = sysread( $socket, $tmp, $max_len );
>    if { $tmp ) {
>       if ( $dccexists == 1 ) {
>          $dccmsglen = sysread( $dccsocket, $dcctmp, $max_len );
>       }
>       if ( $dcctmp ) {
>          print "PRIVMSG $channel $dcctmp\n";
>          print $socket "PRIVMSG $channel $dcctmp\r";
>          $dcctmp = "";
>       }
>       @tmps = split( /:/, $tmp );
>       $command = $tmps[2];
>       @tmps = split( ' ', $tmp );
>       if ( $command =~ /!quit/i ) {
>          print "QUIT\n";
>          print $socket "QUIT\r";
>          $done = 1;
>       }
>       if ( $command =~ /DCC CHAT/i ) {
>          $command =~ s/$a//g;
>          $dccport = $tmps[$#tmps];
>          $dccip = $tmps[$#tmps-1];
>          $dccsocket = IO::Socket::INET->new(
>             Proto => 'tcp',
>             PeerAddr => $dccip,
>             PeerPort => $dccport
>          );
>          if ( $dccsocket ) {
>             $dccexists = 1;
>             $dccsocket->blocking(0);
>             $dccsocket->autoflush(1);
>             print "DCC CHAT\n";
>             print $dccsocket "DCC CHAT\r";
>             print "PRIVMSG $controller :Ready and waiting!\n";
>             print $socket "PRIVMSG $controller :Ready and waiting!\r";
>          } else {
>             print "UNABLE TO ESTABLISH DCC CONNECTION TO $dccip
> $dccport\n";
>             $dccexists = 0;
>          }
>       }
>    }
> }
>
> ------------------- End Second Code Snippet -------------
>
> I believe the problem with the first set of code is that the way
> I was reading from the sockets... ie $tmp = <$socket>... is a
> blocking IO read.  This caused some problems...  With the
> $socket->blocking(0) and the sysread() calls, I should be able
> to read without problems from either one, but now it fails to even open
the
> $dccsocket.  I had reason to believe my router was
> the issue, but I now believe the problem lies elsewhere.  I opened
> all of the ports within the range XChat has requested DCC CHAT on,
> and I've changed it to specifically set $dccip = 'localhost' to
> bypass the router and neither one works.  The second may be due to
> the way XChat opens it's socket.  If it bound it to listen on a
> specific IP then it may not be listening to localhost and I wouldn't be
> able to connect, but the only IP it should listen on
> if that's the case is my '192.168.x.x' IP from my router.  I
> tried setting to that IP as well with no luck.  I will test my
> theory further when I go to work, as I will not have a firewalled
> / NATing router to worry with.  Thank you for the suggestions and
> help.
>
> Stefan
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to