" sys.exit(1) irc = sys.argv[1]...">

Socket.error: [Errno 10054]

import socket, sys

if len(sys.argv) !=3 :
print "Usage: ./supabot.py <host> <port>"
sys.exit(1)

irc = sys.argv[1]
port = int(sys.argv[2])
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((irc, port))
sck.send('NICK supaBOT\r\n')
sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n')
sck.send('JOIN #darkunderground' + '\r\n')
data = ''
while True:
      data = sck.recv(1024)
      if data.find('PING') != -1:
         sck.send('PONG ' + data.split() [1] + '\r\n')
         print data
      elif data.find('!info') != -1:
          sck.send('PRIVMSG #darkunderground supaBOT v1.0 by sourD' + '\r\n')


print sck.recv(1024)

when i run this code i get this error.

socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host

states that the error is on line 16, in data = sck.recv (1024)

+5
source share
3 answers

You need to check the IRC protocol a bit; your IRC session is not considered connected (server) until certain actions are performed that the server will inform your client about the use of IRC protocol codes. And if the server or network is busy when you connect, it will take longer to complete these steps.

, MOTD ( ), . MOTD 376 , IRC , IRC, : (, join).

RECV , IRC 376, , Perl :

 sub chan_join{
  while(my $input = <SOCK>){
    if($input =~ /376/){
      my $talk = "JOIN $channel";
      &send_data($talk);
      &monitor;
    }
    else { print "$input";  }
  }
}

, ? ( , 376, , , PING)

+4

, , , .

, ?

+1

TCP reset (RST) . , :

  • .
  • .

, telnetting .

, (Ethereal, WireShark ..) .

+1

All Articles