IRC 机器人无法识别服务器 - 连接挂起
当我尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有刷新缓冲区。使用 writer.Flush();每次写入后。
示例:
或者
You're not flushing the buffer. use writer.Flush(); after each Write.
Example:
Or