c# - 使用 C# 连接到 IRC 服务器

标签 c# irc tcpclient

我一直在尝试使用简约的 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

查看连接注册。您需要按照以下步骤获取连接:

  1. 传递消息
  2. 昵称消息
  3. 用户留言

您缺少 USER 命令。

关于c# - 使用 C# 连接到 IRC 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3176093/

相关文章:

c# - Paypal API 在指向我的证书文件时失败

C++ 套接字编程 TCP/IP 套接字缓冲区的最大大小?

vb.net - TCP客户端到服务器通信

c# - 如何实现 TcpClient、IPEndPoint、IPAddress 对象的实例化,当作为字符串传递时,为这两种情况实例化 IPv4 和 IPv6 地址

linux - IRCD配置: authentication using a database table

python - 类型错误 : does not support the buffer interface Twitch IRC Chat Bot

c# - OnMouseOver() 不适用于 child

c# - 使用 OpenXML SDK 2.0 在运行时累积 RunProperties

c# - ServiceStack:如何处理错误?

python - 我正在用 Python 创建一个以 Twitch 为中心的 IRC 机器人,但它得到响应的速度很慢。我究竟做错了什么?