I've been trying my hand at a minimalistic IRC bot, but I can never get a connection to work.
I'm doing this via a TcpClient object, which I've seen used in other such projects and those reportedly work.
Here's the code.
private string server = "irc.freenode.net";
private int port = 6667;
private string nick = "testingsharpbot";
private string channel = "testblablabla";
private TcpClient irc;
public ConfigForm() {
InitializeComponent();
}
private void ConnectButton_Click(object sender, EventArgs e) {
this.irc = new TcpClient(this.server, this.port);
using(NetworkStream stream = irc.GetStream()){
using(StreamReader sr = new StreamReader(stream)) {
using(StreamWriter sw = new StreamWriter(stream) {NewLine = "\r\n", AutoFlush = true}) {
sw.WriteLine("NICK " + this.nick);
sw.WriteLine("JOIN " + this.channel);
}
}
}
}
So I wait a bit and then do a /whois on the nickname, but I always get the same reply: user does not exist.
As far as I'm aware, the TcpClient makes the connection and I can then use the NetWorkStream instance to read and write to that connection.
What else do I need to do?