So, I have been trying to make a bot that connects to a local irc server. The problem is that if I call the "Irc.cs" class I made with a constructor like: Irc irc = new Irc("192.168.1.2", 6667); irc.joinChannel("#test")
it does not show up on the irc server channel. The thing is I don't think it failed to connect because if I put Irc irc = new Irc("192.168.1.11", 6667)
(which isn't a server) it throws an exception, but the one that is a server doesn't. I would love if someone could help :) This is the code for "Irc.cs"
public IrcBot(String ip, int port, String nickName)
{
tcpClient = new TcpClient(ip, port);
inputStream = new StreamReader(tcpClient.GetStream());
outputStream = new StreamWriter(tcpClient.GetStream());
outputStream.WriteLine("NICK " + nickName);
outputStream.WriteLine("USER " + nickName + " 8 * : " + nickName);
outputStream.Flush();
}
public void joinRoom(String channel)
{
this.channel = channel;
outputStream.WriteLine("JOIN " + channel);
outputStream.Flush();
}
One important thing here is that IRC uses CR/LF instead of LF that StreamWriters use, so you would need to create a StreamWriter like this:
writer = new StreamWriter(stream) { NewLine = "\r\n" };
That way it will send CR/LF at the end of each line.