开发者

IRC client in python

开发者 https://www.devze.com 2023-01-24 16:17 出处:网络
I\'m writing python code for IRC client. I want to understand how IRC client and server communicating each other.

I'm writing python code for IRC client.

I want to understand how IRC client and server communicating each other.

Can anyone give me good tutorial or IRC communication architecture to understand it 开发者_Go百科in depth?

Thanks


The IRC RFC documentation is an important reference, but the most helpful first introduction I've found on communication between IRC client and server was really simple.

First, you need access to a *nix shell (e.g. ssh into your web host running Linux).

In the command line, open up a direct connection to an IRC server using the program 'nc'. Then you can type RFC commands directly, and see the response. Try typing

$ nc wright.freenode.net 6667
PASS whateveryoulike
NICK yournick
USER username 0 * :Real Name

There is output from the server amidst this, but now you've logged into and "registered" your user. Note: your nick isn't registered (ala NickServ), I'm referring to registering a user as outlined in section 3.1 of the RFC 2812 IRC Client Protocol.

You can now join a channel:

JOIN #yourtestchannel

See who's in the channel:

WHO #yourtestchannel

Send yourself a msg:

PRIVMSG yournick Message Text Here

Chat into the channel (send the channel a msg):

PRIVMSG #yourtestchannel Message Text Here

This is especially helpful if you're connected to the same server and channel with a different nick in a real IRC client. You can chat with yourself and msg one nick to the other, and see the "raw" IRC output that you'll have to parse to write your own client or bot.

For example, someone chatting in a channel looks something like this:

:SomeDude28!SomeDude28@hoststring-with_various_parts PRIVMSG #channel :Hey guys, what's up?

Using the RFC, you can play around with whatever functionality you want, and, more importantly, figure out how you'll need to parse things.

Oh, and don't forget to PONG occasionally, or when prompted with a PING, to avoid ping timeout.


If you want to reinvent the wheel, then you have to implement the RFC and do everything from scratch.

If you don't want to do that and would require some level of abstraction to ease your development (and which you should), then see Twisted.

There is also a Python IRC client library.


For most protocols a good way to start is to look for a document called RFC. There's one for many protocols and it defines - in depth - how it should behave.

You can find the one for IRC here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号