Connecting to IRC using socket module

Dag Hansteen d-hanst at online.no
Fri Oct 22 15:56:16 EDT 2004


Hello!

Somehow I dont make this work, can anyone please 
correct me?

There is no error, but it just kinda halts after I get "NOTICE AUTH: *** Found your hostname", I assume theres something with the PONG reply, but I can't figure it out.


# CODE:

from socket import *

host = "oslo.no.eu.undernet.org"
port = 6667
buf = 1024
addr = (host, port)

first = 'NICK dagan'
second = 'USER dag "" "oslo.no.eu.undernet.org" :python bot'

sock = socket(AF_INET, SOCK_STREAM)


sock.connect(addr)
sock.sendto(first, addr)
print "-> "+first

sock.sendto(second, addr)
print "-> "+second


while 1:
    data, addr = sock.recvfrom(buf)
    
    f = open("debug.txt", "w")
    f.write(data+"\n")
    
    if data.startswith("PING :"):
        sock.send("PONG :"+data[6:])
        break
    
    else:     
        print "<- "+data
        print addr

print "I hope I soon will see this message.. yes, this message! woohoo"

sock.send("join #scripting")

while 1:
    data, addr = sock.recvfrom(buf)
    print "<- "+data
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041022/040cba3b/attachment.html>


More information about the Python-list mailing list