V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
SystemLight
V2EX  ›  Python

IRC 协议中发送什么样的数据包可以发送给频道中的所有人消息, socket 编程该如何接收频道中的消息呢?

  •  
  •   SystemLight ·
    SystemLight · 2020-05-29 16:44:41 +08:00 · 1906 次点击
    这是一个创建于 1399 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有没有人用 IRC 协议,IRC 协议中发送什么样的数据包可以发送给频道中的所有人消息,socket 编程该如何接收频道中的消息呢?

    4 条回复    2020-06-01 11:47:51 +08:00
    est
        1
    est  
       2020-05-29 17:05:58 +08:00
    这个跟数据包无关吧。irc daemon 选择如何传递消息。
    ysc3839
        2
    ysc3839  
       2020-05-30 04:22:21 +08:00 via Android
    怀疑这是个 X-Y Problem,建议你说一下最终的目的。
    你只是想自行研究学习 IRC 协议吗?还是说要实现别的功能?如果是后者建议使用现成的 IRC 库。
    SystemLight
        3
    SystemLight  
    OP
       2020-06-01 11:26:24 +08:00
    @ysc3839 实际上我现在可以发送信息到 IRC 服务器, 我选择的服务器是 irc.gitter.im/6697, 频道是#systemlight-madtornado/community,irc.gitter.im 提供了 web 端访问 : https://gitter.im/systemlight-madtornado/community

    我现在可以将消息发送到这个频道中,代码实现,协议参考地址 https://tools.ietf.org/html/rfc1459:
    import socket
    import ssl

    ircbot = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    ircbot = ssl.wrap_socket(ircbot)

    ircbot.connect(("irc.gitter.im", 6697))
    ircbot.send("PASS 1f3f4e0fd544731b4fedc7ce096a2a6a7447aef3\n".encode())
    print(ircbot.recv(2040))
    ircbot.send("USER test test test :test\n".encode())
    ircbot.send("NICK test\n".encode())
    ircbot.send("JOIN #systemlight-madtornado/community\r\n".encode())
    # ircbot.send('PRIVMSG #systemlight-madtornado/community :hello me\r\n'.encode())

    while True:
    data = ircbot.recv(4096)

    if data.find(b'PING') != -1:
    ircbot.send(b'PONG ' + data.split()[1] + b'\r\n')

    if data:
    print(data)


    问题:如何可以接收到别人发送来的信息,我尝试使用一个工具 hexchat 往频道中发送消息,web 端可以获取到该消息,但是我的程序没有收到任何的来自 IRC 服务器的反馈,但是我可以收到它发送给我的一些心跳包 ping-pong
    ysc3839
        4
    ysc3839  
       2020-06-01 11:47:51 +08:00 via Android
    @SystemLight 你好像没有明确表示是不是要研究学习 IRC 协议,如果是的话我只能说我没研究过,我都是使用现成的库的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3045 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 12:48 · PVG 20:48 · LAX 05:48 · JFK 08:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.