Python
  Home arrow Python arrow Page 2 - Python and IRC
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Python and IRC
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 29
    2005-02-16

    Table of Contents:
  • Python and IRC
  • Hello IRC World
  • Can You Hear Me?
  • I Can Hear You!
  • IRC Mathematics

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Python and IRC - Hello IRC World
    (Page 2 of 5 )

    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' )
    irc.close()

    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


       · Hey, all. I thought this would be a unique topic to write about. I haven't seen...
       · very nice article, it's very rare to see someone talking about writing scripts for...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway