2015-08-30 22 views
2

我有源irc客戶端從一些網站。這是一些代碼:C#irc客戶端streamwriter只發一個字

 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(); 
        } 
       } 
      } 
     } 
    } 
} 

連接的更迭,但是當我寫像發送消息「世界,你好」只發送「你好」。這段代碼有什麼問題?也許必須先編碼字符串?或?請幫助我。謝謝:)

+0

嘗試在「Hello」之前添加冒號(':')。 – cubrr

+0

@cubrr wooooooooowwwww。完美工作:D。非常感謝。 – kresek

回答

1

您的IRC命令的最後一個參數應該以冒號字符(:)爲前綴。否則,對參數的解析將在第一個空白處結束。

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

是的,我嘗試過,完美地工作。非常感謝:D – kresek