C# irc 客户端 Streamwriter 只发送一个字

标签 c# irc streamwriter.write

我有来自某个网​​站的源irc客户端。这是一些代码:

     using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Net;
        using System.Net.Sockets;
        using System.IO; 
        using System.Text.RegularExpressions; 
    namespace tes_irc
    {
        class Program
        {
            static string[] usuarios; 
            static void Main(string[] args)
            {

                NetworkStream conexion;
                TcpClient irc;
                StreamReader leer_datos;
                StreamWriter mandar_datos;

                string host = "irc.dal.net";
                string nickname = "testing";
                string canal = "#gsgsge";


        string code = "";
            leer_datos = new StreamReader(conexion);
            mandar_datos = new StreamWriter(conexion);

            mandar_datos.WriteLine("NICK " + nickname);
            mandar_datos.Flush();
            mandar_datos.WriteLine("USER " + nickname + " 1 1 1 1");
            mandar_datos.Flush();
            mandar_datos.WriteLine("JOIN " + canal);
            mandar_datos.Flush();
            while (true) // Mi bucle eterno
            {
                while ((code = leer_datos.ReadLine()) != null)
                {
                    Console.WriteLine("Code : " + code);
                    Match regex = Regex.Match(code, "PING(.*)", RegexOptions.IgnoreCase);

                    if (regex.Success)
                    {
                        Console.WriteLine("hehe");
                        string te_doy_pong = "PONG " + regex.Groups[1].Value;
                        mandar_datos.WriteLine(te_doy_pong);
                        mandar_datos.Flush();
                    }

                    regex = Regex.Match(code, ":(.*) 353 (.*) = (.*) :(.*)", RegexOptions.IgnoreCase);
                    if (regex.Success)
                    {
                        string usuarios_lista = regex.Groups[4].Value;
                        usuarios = usuarios_lista.Split(' ');
                        foreach (string usuario in usuarios)
                        {
                            Console.Write("[+] User : " + usuario);
                        }

                        mandar_datos.WriteLine("PRIVMSG" + " " + canal + " " + "Hello World");
                        mandar_datos.Flush();
                    }
                }
            }
        }
    }
}

连接成功,但是当我编写“Hello world”之类的发送消息时,只需发送“Hello”。这段代码有什么问题?也许必须先对字符串进行编码?或者?请帮助我。先谢谢了:)

最佳答案

IRC 命令的最后一个参数应以冒号字符 (:) 为前缀。否则参数的解析将在第一个空格处结束。

mandar_datos.WriteLine("PRIVMSG" + " " + canal + " " + ":Hello World");

关于C# irc 客户端 Streamwriter 只发送一个字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32295267/

相关文章:

c# - 找不到命名空间并且无法添加引用

javascript - 我需要 Node 客户端中客户端之间的路由数据来纠正连接的用户

c# - 如何用 StreamWriter 写特殊字符 (é, è)?

c# - 正则表达式 C# 按精确顺序匹配两个单词的字符串并返回不匹配单词的捕获

c# - 如何在不创建 form1 的新实例的情况下在 form2 中调用 form1 的方法

python - 在不重新启动主脚本的情况下加载/重新加载 Python 中的部分代码

c# - StreamWriter.Write 不写入文件;没有抛出异常

c# - CaSTLe 动态代理不将自定义属性写入代理

python : Check if IRC connection is lost (PING PONG? )