Home arrow Python arrow Page 2 - Python and IRC

Hello IRC World - Python

IRC is becoming an increasingly popular medium for communication. In this article, Peyton McCullough explains how to make Python and IRC work together.

  1. Python and IRC
  2. Hello IRC World
  3. Can You Hear Me?
  4. I Can Hear You!
  5. IRC Mathematics
By: Peyton McCullough
Rating: starstarstarstarstar / 34
February 16, 2005

print this article



Our first task is to connect to an IRC network. To do this, we must first create a socket. Then, we must connect to the network, and, finally, we must complete a few short steps to become eligible to interact with other users.

import socket

network = 'irc.insert.a.network.here'
port = 6667
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
irc.send ( 'NICK PyIRC\r\n' )
irc.send ( 'USER PyIRC PyIRC PyIRC :Python IRC\r\n' )
irc.send ( 'QUIT\r\n' )

Although the code demonstrates the absolute basics, it doesn't do anything special. In fact, the server you connect to might not even acknowledge the data you send it until after a few seconds which we do not allow for in the script. Don't worry though, we will soon take a look at a fully functional script after we tackle the very basics.

The first piece of data we send to it sets our nickname. Notice how we suffix each outgoing message with a carriage return and line feed ( "\r\n" ). Take note of this because it is very important. We then specify our username ( "PyIRC" ), host name ( "PyIRC" ), server name ( "PyIRC" ) and real name ( "Python IRC" ) in the next outgoing line.  Finally, we issue the "QUIT" command and close the connection.

You should also take note of the colon before "Python IRC." Colons tell the server that the attribute will possibly be made up of multiple words.

We will use and develop this skeleton throughout the remainder of the article, so it is important that you understand it.

>>> More Python Articles          >>> More By Peyton McCullough

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: