Hardware Reference
In-Depth Information
As usual, create a new project in IDLE or a text editor and enter the shebang line along with
a comment describing the purpose of the program:
#!/usr/bin/env python
# IRC Channel Checker, written for the Æ
Raspberry Pi User Guide by Tom Hudson
Next, import the modules required by the program— sys , socket and time —with the fol-
lowing line:
import sys, socket, time
You used the sys and time modules previously in the Raspberry Snake program, but you
have not yet used socket . he socket module provides Python with the ability to open,
close, read from and write to network sockets—giving Python programs rudimentary net-
working capabilities. It's the socket module that provides this example with its ability to
connect to a remote IRC server.
here are some constants needed for this program to operate. Constants are like variables in
that they can have values assigned to them—but unlike variables, the value in a constant
shouldn't change. To help diferentiate a constant from a variable, it's good practice to use all-
capital letters for their names—that way it's easy to see at glance whether a particular section
of the code is using a constant or a variable. Type the following two lines into the program:
RPL_NAMREPLY = '353'
RPL_ENDOFNAMES = '366'
hese are IRC status codes , provided by the server to indicate when particular operations have
completed. hese are used by the program to know when it has received the required list of
names from the IRC server. Next, set up the variables for the server connection by entering
the following lines:
irc = {
'host' : 'chat.freenode.net',
'port' : 6667,
'channel' : '#raspiuserguide',
'namesinterval' : 5
}
Search WWH ::




Custom Search