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

2020-05-29 16:44:41 +08:00
 SystemLight

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

1929 次点击
所在节点    Python
4 条回复
est
2020-05-29 17:05:58 +08:00
这个跟数据包无关吧。irc daemon 选择如何传递消息。
ysc3839
2020-05-30 04:22:21 +08:00
怀疑这是个 X-Y Problem,建议你说一下最终的目的。
你只是想自行研究学习 IRC 协议吗?还是说要实现别的功能?如果是后者建议使用现成的 IRC 库。
SystemLight
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
2020-06-01 11:47:51 +08:00
@SystemLight 你好像没有明确表示是不是要研究学习 IRC 协议,如果是的话我只能说我没研究过,我都是使用现成的库的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/676760

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX