IRC 客户端 - JOIN 没有回复

发布于 2024-12-08 01:36:17 字数 944 浏览 0 评论 0原文

我正在用 C++ 编写一个 IRC 客户端(在 SFML 库的帮助下),但它的行为很奇怪。我发送 NICK 和 USER 命令,并且可以连接到服务器,但是 JOIN 命令发生了许多奇怪的事情,我必须编写“神奇地工作的随机代码”来解决。我非常确定这些命令也遵守 IRC RFC。

我知道套接字正在发送它们应该发送的内容,并且我已经使用 Wireshark 对其进行了验证,因此我在这里发布的是数据包的消息是什么。在下面的例子中,套接字已经连接到 IRC 服务器(在本例中是 irc.freenode.net)

这有效:

char mess[] ="NICK lmno \n\rUSER lmno 0 * :lmno\n\rJOIN #mytest\n\r";
Socket.Send(mess, sizeof(mess));

这不起作用:

char msg[] = "NICK lmno \r\nUSER lmno 0 * :lmno \r\n";
char msga[] = "JOIN #mytest \r\n";
Socket.Send(msg, sizeof(msg));
Socket.Send(msga, sizeof(msga));

但奇怪的是,这有效:

char msg[] = "NICK lmno \r\nUSER lmno 0 * :lmno \r\n";
char msga[] = "JOIN #mytest \r\n";
Socket.Send(msg, sizeof(msg));
Socket.Send(msga, sizeof(msga));
Socket.Send(msga, sizeof(msga));

我确实对这个主题做了一些研究,但似乎没有人有同样的问题。奇怪的是,当我在 telnet 中尝试这个时,我只需要发送 JOIN 一次。 有人能给我一些建议吗?

谢谢, 超导荧光指数

I am writing a IRC client in C++ (with the help of the SFML library), but it is behaving strangely. I send the NICK and USER commands and I can connect to the server, but the JOIN command has many strange thing happening that I have to write "Random code that magically works" to solve. I am pretty sure that the commands adhere to the IRC RFC as well.

I know that the sockets are sending what they are supposed to send and I have verified it with Wireshark, so what I post here is what the message of the packet is. In the following examples the socket is already connected to the IRC server (which in this case is irc.freenode.net)

This works:

char mess[] ="NICK lmno \n\rUSER lmno 0 * :lmno\n\rJOIN #mytest\n\r";
Socket.Send(mess, sizeof(mess));

This does not:

char msg[] = "NICK lmno \r\nUSER lmno 0 * :lmno \r\n";
char msga[] = "JOIN #mytest \r\n";
Socket.Send(msg, sizeof(msg));
Socket.Send(msga, sizeof(msga));

But curiously this works:

char msg[] = "NICK lmno \r\nUSER lmno 0 * :lmno \r\n";
char msga[] = "JOIN #mytest \r\n";
Socket.Send(msg, sizeof(msg));
Socket.Send(msga, sizeof(msga));
Socket.Send(msga, sizeof(msga));

I did do some research on this topic and no one seems to have the same problem. Stranger is that when I tried this in telnet, I only have to send JOIN once.
Is anyone able to give me some advice?

Thanks,
SFI

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏雨凉 2024-12-15 01:36:17

它可能与 c 字符串末尾的终止字符“\0”有关。尝试

Socket.Send(msg, sizeof(msg) - 1);
Socket.Send(msga, sizeof(msga) - 1);

It might have to do with the terminating '\0' character at the end of a c-string. Try

Socket.Send(msg, sizeof(msg) - 1);
Socket.Send(msga, sizeof(msga) - 1);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文