Input encoding for the IRC server

I have been messing with a C#/Mono library which wouldn’t let my bot client connect properly. It would send back an error like this:
As you may notice, it somehow magically has a hidden byte of data in front of the word PASS. However my library was just passing in UTF-8 encoded commands.
When i switched my library to use ASCII encoding it magically started working so i kept it that way after a long day of double checking and messing around, but my real question is what exact encoding does the server expect, and why is it not listed on the IRC help page of Twitch?

Thanks in advance,

I had the same issue with UTF-8 but bypassed it by sending an empty raw message before PASS

The server accepts utf-8. ascii is a subset of utf-8, so it also works fine. I presume your library was sending the UTF-8 BOM before the message, causing the issue you saw.

Thanks for your replies. Reading up on the wiki about the BOM character this does seem to fit with the example i have shown. I should read it out in HEX to confirm it later. It might just be the cause of the problem. I have no idea why it would put the character there when i haven’t asked for it. But it might just be part of the serializer of the library.

If this is the case, my solution would be to flush the stream before i start sending my first message. I imagine it would do the same as whatever Freddy did to get it to work.

Either way, if the server default is UTF-8 (or it expects UTF-8 at least) it might still be a good idea to write it on the help page in any rate. Maybe this BOM character could be mentioned as well. Could save a bunch of people a day worth of headaches over a single invisible set of bytes :expressionless:

Thanks for the help so far, i will post the results of my flush before sending data to confirm if it worked.

Ok after some fiddling around i found out that flushing an empty string does not help. The proper way to do the encoding is to use the following:

using System.Text;
var encoding = new UTF8Encoding(false);
_Writer = new StreamWriter(_TcpClient.GetStream(), encoding);

Noteworthy is that by default most people use the following:

encoding = System.Text.Encoding.UTF8;

the problem with this is that it sends the BOM variable. While the example i just provided does not. For more info:
Stackoverflow link

I hope this clears up some issues for others in the future. Please mark up somewhere that twitch IRC wants to get UTF-8 and WILL stumble over BOM character(s) in front of the message. This should get people to think about BOM and if it applies to them or not.

Thanks in advance,

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.