IRC 机器人无法识别服务器 - 连接挂起

发布于 2024-10-30 00:54:08 字数 1144 浏览 1 评论 0原文

当我尝试使用 C# 中的简单 IRC 机器人连接到 freenode 时,我收到以下消息:

:asimov.freenode.net 注意 * :* 查找您的主机名...

:asimov.freenode.net 注意 * :* 检查身份

:asimov.freenode.net 注意 * :* 无法查找您的主机名

:asimov.freenode.net 注意 * :* 无识别响应

然后大约 30 秒后,程序终止。

我尝试在 NICK 消息之前发送 USER 消息,并且还尝试手动将回车符“\r\n”附加到行尾,而不是在 StreamWriter 选项中指定它。关于可能导致这种行为的其他事情有什么想法吗?

这是我当前的代码:

        socket = new TcpClient(host, port);
        socket.ReceiveBufferSize = 1024;
        Console.WriteLine("Connected");
        NetworkStream stream = socket.GetStream();
        reader = new StreamReader(stream);
        writer = new StreamWriter(stream) { NewLine = "\r\n", AutoFlush = true };
        writer.Write("NICK " + user);
        writer.Write("USER " + user + " 8 * :" + user);
        writer.Write("JOIN " + chan);
        //System.Threading.Thread.Sleep(5000);

        while(running)
        {
            line = reader.ReadLine();
            Console.WriteLine(line);
        }

**已修复 - 使用 .WriteLine 修复了它。谢谢!

When I try and connect to freenode using a simple IRC bot in C#, I get the following messages:

:asimov.freenode.net NOTICE * :* Looking up your hostname...

:asimov.freenode.net NOTICE * :* Checking Ident

:asimov.freenode.net NOTICE * :* Couldn't look up your hostname

:asimov.freenode.net NOTICE * :* No Ident response

And then after about 30 seconds, the program terminates.

I have tried sending the USER message before the NICK message, and also have tried manually appending the carriage return "\r\n" to the end of the line instead of specifying it in the StreamWriter options. Any ideas as to other things that might cause this behavior?

Here is my current code:

        socket = new TcpClient(host, port);
        socket.ReceiveBufferSize = 1024;
        Console.WriteLine("Connected");
        NetworkStream stream = socket.GetStream();
        reader = new StreamReader(stream);
        writer = new StreamWriter(stream) { NewLine = "\r\n", AutoFlush = true };
        writer.Write("NICK " + user);
        writer.Write("USER " + user + " 8 * :" + user);
        writer.Write("JOIN " + chan);
        //System.Threading.Thread.Sleep(5000);

        while(running)
        {
            line = reader.ReadLine();
            Console.WriteLine(line);
        }

**Fixed - using .WriteLine fixed it. Thanks!

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

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

发布评论

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

评论(1

不美如何 2024-11-06 00:54:08

您没有刷新缓冲区。使用 writer.Flush();每次写入后。

示例:

writer.Write("NICK {0}\r\n", user);
writer.Flush();

或者

writer.WriteLine("NICK {0}", user);
writer.Flush(); // Maybe here you will not need to flush because of the autoflush

You're not flushing the buffer. use writer.Flush(); after each Write.

Example:

writer.Write("NICK {0}\r\n", user);
writer.Flush();

Or

writer.WriteLine("NICK {0}", user);
writer.Flush(); // Maybe here you will not need to flush because of the autoflush
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文