0

これはコードです:

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# の例。

参加したチャンネルにメッセージを送信するにはどうすればよいですか? 1つのメッセージを送信したいのですが、次のステップがキューにメッセージを追加することである場合、それらは自動的に1つずつ送信されます。

どうすればできますか?

4

2 に答える 2

1

JOINしたサーバーに送信したからといって、すぐにチャンネルに参加できるわけではありません。実際のチャネルに入るまで待機し (サーバーから JOIN コマンドが返されるのを待ちます)、privmsg を送信する必要があります。

于 2013-09-13T22:11:46.297 に答える