这是代码:
private void connectToIrc()
{
//Connect to irc server and get input and output text streams from TcpClient.
nick = textBox1.Text;
owner = textBox2.Text;
server = textBox3.Text;
port = Convert.ToInt32(textBox4.Text);
chan = "#" + textBox5.Text;
sock.Connect(server, port);//server, port);
richTextBox1.Invoke((MethodInvoker)delegate
{
ColorText.AppendText(richTextBox1, "Server: ", Color.Green);
ColorText.AppendText(richTextBox1, server+" ", Color.Red);
ColorText.AppendText(richTextBox1, "Port: ", Color.Green);
ColorText.AppendText(richTextBox1, port.ToString() + Environment.NewLine + Environment.NewLine, Color.Red);
});
if (!sock.Connected)
{
Console.WriteLine("Failed to connect!");
return;
}
input = new System.IO.StreamReader(sock.GetStream());
output = new System.IO.StreamWriter(sock.GetStream());
//Starting USER and NICK login commands
output.Write(
"USER " + nick + " 0 * :" + owner + "\r\n" +
"NICK " + nick + "\r\n"
);
output.Flush();
//Process each line received from irc server
//buf = input.ReadLine();
while ((buf = input.ReadLine()) != null)
{
buf = buf + Environment.NewLine;
//Display received irc message
//Console.WriteLine(buf);
richTextBox1.Invoke((MethodInvoker)delegate
{
ColorText.AppendText(richTextBox1, buf,Color.Black);
});
if (buf.StartsWith("ERROR")) break;
//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;
//After server sends 001 command, we can set mode to bot and join a channel
if (buf.Split(' ')[1] == "001")
{
output.Write(
"MODE " + nick + " +B\r\n" +
"JOIN " + chan + "\r\n" + "PRIVMSG " + chan + " :hello"
);
output.Flush();
}
buf = input.ReadLine();
}
}
我将这部分添加到代码中: + "PRIVMSG" + chan + " :hello" 但它什么也没做,我在频道中看不到任何“hello”。
我在这个网站上使用了这个例子:
http://jakash3.wordpress.com/2012/02/13/simple-vb-net-and-csharp-irc-client/
C# 示例。
加入频道后如何向频道发送消息?我想发送一条消息,如果它的下一步工作是将消息添加到队列中,它们将被一个一个地自动发送。
我该怎么做 ?