我一直在尝试一个简约的 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 实例读取和写入该连接。
我还需要做什么?