通过SSL建立与IRC的连接

时间:2014-10-23 15:13:54

标签: c# ssl irc

有人可以告诉我一个如何与IRC服务器建立SSL连接的示例吗?

我曾尝试阅读有关SslStream的内容,但我感觉不到。我可以使用它连接到没有SSL的IRC:

        sock.Connect(server, port);
        if (!sock.Connected) {
            Console.WriteLine("Failed to connect!");
            return;
        }
        input = new System.IO.StreamReader(sock.GetStream());
        output = new System.IO.StreamWriter(sock.GetStream());

        output.Write("USER " + nick + " 0 * :" + owner + "\r\n" + "NICK " + nick + "\r\n");
        output.Flush();

        //Process each line received from irc server
        for (buf = input.ReadLine(); ; buf = input.ReadLine()) {
            //Display received irc message
            //Console.WriteLine(buf);
            if (buf.Split(' ')[1] == "332") {
                Console.WriteLine(buf.Split(new char[] { ' ' }, 5)[4]);
            }
            //Send pong reply to any ping messages
            if (buf.StartsWith("PING ")) {
                output.Write(buf.Replace("PING", "PONG") + "\r\n"); output.Flush();
            }
            if (buf[0] != ':') continue;
            if (buf.Split(' ')[1] == "001") {
                output.Write(
                    "MODE " + nick + " \r\n" +
                    "JOIN " + chan + "\r\n"
                );
                output.Flush();
            }
        }
    }
}

1 个答案:

答案 0 :(得分:-1)

试试这个:

conn, err = tls.Dial("tcp", HOST+":"+PORT, &tls.Config{InsecureSkipVerify: true})