sockets and classes

Steve Holden sholden at holdenweb.com
Tue Jul 31 16:39:30 EDT 2001


"TheDustbustr" <thedustbustr at aol.com> wrote in message
news:20010731161148.05170.00001954 at ng-fw1.aol.com...
> Having quite a bit of trouble with sockets and classes lately.  I am
writing an
> IRC bot, heres the trouble code:
>
> #BEGIN CODE BLOCK
> import socket, string, sys, errno, thread
> HOST = 'liberty.nj.us.dal.net'
> PORT = 7000
> NICK='Dustin2'
> REAL='Ima Bot'
> QUITMSG='Bye'
> IDENT='hacker'
>
> class Irc:
>     def __init__(self, host, port):
>         self.host = host
>         self.port = port
>
>     def connect(self):
>         print 'Connecting to %s:%s' % (self.host, self.port)
>         self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>         self.sock.connect((self.host, self.port))
>
>     def sendcmd(self, cmd):
>         self.sock.send(cmd)
>
> irc=Irc(HOST, PORT)
> irc.connect()
>
> print "Sending USER"
> irc.sendcmd('USER %s localhost localhost :%s\n' % (IDENT, REAL))
> print "Sending NICK"
> irc.sendcmd('NICK %s\n' % NICK)
> print "Sending JOIN"
> irc.sendcmd('JOIN #Dustin1')
> #END CODE BLOCK
>
> I don't get error messages while executing irc.sendcmd(), but it doesnt
work.
> I should recieve a response fromt he server after sending USER and NICK,
then
> another response after sending JOIN.  But, I get nothing.  Whats up!?
> PS:  This is my first attempt to program using classes, and perhaps I'm
not
> doing it right?
>
You seem to be doing OK, but ask yourself how you would *know* about the
response, when nothing in your code actually reads the socket to see what's
coming back?

In the general case you need to be able to recognise the end of a response,
and I don't know enough about IRC to help you with that, but try scattering
the odd recv() call in your code to see whether the host is sending
responses. The fact that you aren't seeing error messages is at least
encouraging!

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list