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]



Reply via email to