Python
  Home arrow Python arrow Page 3 - Python and IRC
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 33
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Python and IRC - Can You Hear Me?
    ( Page 3 of 5 )

    Now that we know how to connect, our next task is joining a channel and sending a message to its occupants. This is suprisingly easy.

    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 ( 'JOIN #pyirc\r\n' )
    irc.send ( 'PRIVMSG #pyirc :Can you hear me?\r\n' )
    irc.send ( 'PART #pyirc\r\n' )
    irc.send ( 'QUIT\r\n' )
    irc.close()

    Note that, again, the code will probably not perform the instructions we gave it, for the same reason as last time. However, the above code would ideally join the channel #pyirc and say "Can you hear me?" Let's break the code down to see how it works. The first few lines should already look familiar, and the last few lines should look familiar as well. We wrote them in the previous section. However, the "JOIN," "PRIVMGS," and "PART" lines are new. They simply join the channel, send a message to the channel and leave the channel, respectively.

    To join multiple channels, just issue the "JOIN" command again. When sending a message, be sure to specify the name of the channel in the "PRIVMSG" command. You can also message another user with the "PRIVMSG" command.

    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 ( 'PRIVMSG Jimbo :Can you hear me?\r\n' )
    irc.send ( 'QUIT\r\n' )
    irc.close()



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

       

    PYTHON ARTICLES

    - 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
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT