IRC Bot does not authenticate with server - connection hangs

When I try to connect to freenode using a simple IRC bot in C #, I get the following messages:

: asimov.freenode.net NOTICE *: * Searching for your hostname ...

: asimov.freenode.net NOTICE *: * ID Verification

: asimov.freenode.net NOTICE *: * Could not find your hostname

: asimov.freenode.net NOTICE *: * No Ident response

And then after about 30 seconds, the program terminates.

I tried to send the USER message before the NICK message, and also tried to manually add the carriage return "\ r \ n" to the end of the line instead of specifying StreamWriter in the parameters. Any ideas on other things that might trigger this behavior?

Here is my current code:

socket = new TcpClient(host, port); socket.ReceiveBufferSize = 1024; Console.WriteLine("Connected"); NetworkStream stream = socket.GetStream(); reader = new StreamReader(stream); writer = new StreamWriter(stream) { NewLine = "\r\n", AutoFlush = true }; writer.Write("NICK " + user); writer.Write("USER " + user + " 8 * :" + user); writer.Write("JOIN " + chan); //System.Threading.Thread.Sleep(5000); while(running) { line = reader.ReadLine(); Console.WriteLine(line); } 

* * Bugfix - using .WriteLine fixed this. Thanks!

+4
source share
1 answer

You are not flushing the buffer. use writer.Flush (); after each entry.

Example:

 writer.Write("NICK {0}\r\n", user); writer.Flush(); 

or

 writer.WriteLine("NICK {0}", user); writer.Flush(); // Maybe here you will not need to flush because of the autoflush 
+3
source

Source: https://habr.com/ru/post/1346479/


All Articles