我有来自某个网站的源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/