我一直在尝试使用简约的 IRC 机器人,但我永远无法连接到工作。
我通过 TcpClient 对象执行此操作,我已经看到该对象在其他此类项目中使用,并且据报道这些项目有效。
这是代码。
private string server = "irc.freenode.net";
private int port = 6667;
private string nick = "testingsharpbot";
private string channel = "testblablabla";
private TcpClient irc;
public ConfigForm() {
InitializeComponent();
}
private void ConnectButton_Click(object sender, EventArgs e) {
this.irc = new TcpClient(this.server, this.port);
using(NetworkStream stream = irc.GetStream()){
using(StreamReader sr = new StreamReader(stream)) {
using(StreamWriter sw = new StreamWriter(stream) {NewLine = "\r\n", AutoFlush = true}) {
sw.WriteLine("NICK " + this.nick);
sw.WriteLine("JOIN " + this.channel);
}
}
}
}
所以我等了一下,然后对昵称执行/whois,但我总是得到相同的回复:用户不存在。
据我所知,TcpClient 建立连接,然后我可以使用 NetWorkStream 实例读取和写入该连接。
我还需要做什么?
最佳答案
首先,我建议您查看相应的 RFC:
http://www.faqs.org/rfcs/rfc2812.html
查看连接注册。您需要按照以下步骤获取连接:
- 传递消息
- 昵称消息
- 用户留言
您缺少 USER 命令。
关于c# - 使用 C# 连接到 IRC 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3176093/