c# – 为什么我的IRC机器人没有连接?
发布时间:2020-12-15 07:46:56 所属栏目:百科 来源:网络整理
导读:public static string SERVER = "irc.rizon.net";private static int PORT = 6667;private static string USER = "Test C# Irc bot";private static string NICK = "Testing";private static string CHANNEL = "#Test0x40"; public static void Main(string[
public static string SERVER = "irc.rizon.net"; private static int PORT = 6667; private static string USER = "Test C# Irc bot"; private static string NICK = "Testing"; private static string CHANNEL = "#Test0x40"; public static void Main(string[] args) { NetworkStream stream; TcpClient irc; StreamReader reader; StreamWriter writer; irc = new TcpClient(SERVER,PORT); stream = irc.GetStream(); reader = new StreamReader(stream); writer = new StreamWriter(stream); writer.WriteLine("NICK " + NICK); writer.Flush(); writer.WriteLine("JOIN " + CHANNEL); writer.Flush(); Console.ReadKey(true); } 为什么我的IRC机器人没有连接? 解决方法
IRC协议需要CR / LF对,而StreamWriter的默认行为只是换行.您应该像这样创建StreamWriter:
writer = new StreamWriter(stream) { NewLine = "rn",AutoFlush = true }; 此外,您可能应该在加入频道之前使用USER命令指定用户名,但我不确定是否完全有必要: writer.WriteLine("USER username +mode * :Real Name"); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |