Twitch irc connection procedure(Solved)

Greeting, im new here and having some trouble accessing the twitch irc. According to the documentation you should receive your first messages after a succesfull login to the irc server, altough this doesnt seem to happen in my case. Could someone please point me at what might be wrong ?

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace testingIRC
class Program
static void Main(string[] args)
TcpClient Client = new TcpClient();
Client.Connect(“”, 6667);
StreamReader sr = new StreamReader(Client.GetStream());
StreamWriter sw = new StreamWriter(Client.GetStream());
sw.WriteLine(“PASS oauth:[tokenreplacement]”);
sw.WriteLine(“NICK [nickname replacement]”);
while (true)
string m = sr.ReadLine();

Like most IRC servers, you will only received messages for rooms that you have joined.

Your code suggests that you didn’t join any rooms.

So a

sw.WriteLine(“/join #someroom");

Should be sent after your nick/pass has validated (after MOTD)

Are you even receiving the connection registration mesages after a successful login? 001 rokuhodo_ :Welcome, GLHF! 002 rokuhodo_ :Your host is 003 rokuhodo_ :This server is rather new 004 rokuhodo_ :- 375 rokuhodo_ :- 372 rokuhodo_ :You are in a maze of twisty passages, all alike. 376 rokuhodo_ :>

Also, try flushing your stream after every write so that you can read/write right away.

Wait I just realized, you’re reading from the buffer after you’re already logged into the IRC server so you won’t receive the registration messages. Create a thread to read from the buffer and start the thread before you log into the server. Then log into server and you should see the registration messages.

So, something like this:

private void
    ExceptionUtil.ThrowIfNull(irc_user, nameof(irc_user), QuickDisconnect);
    ExceptionUtil.ThrowIfInvalid(irc_user.nick, nameof(irc_user.nick), QuickDisconnect);
    ExceptionUtil.ThrowIfInvalid(irc_user.pass, nameof(irc_user.pass), QuickDisconnect);

    stream = new NetworkStream(socket);
    if (port == 443)
        stream = new SslStream(stream, false);

    OnSocketConnected.Raise(this, EventArgs.Empty);

    reader_thread = new Thread(new ThreadStart(ReadStream));

    while (!reading);

    Send("PASS oauth:" + irc_user.pass);
    Send("NICK " + irc_user.nick);

You are correct i am not receiving any registration messages. I have tried to start the reading process in a separate thread before attempting to send the oauth token and the user nick. Sadly its stil not receiving any registration messages. I also have been running a wireshark scan to make sure that a connection is started and i definatly see the handshake procedure between the twitch server and my client. I have also tried to join a channel after the login and the bot isnt appearing in the twitch channel as a member which makes me think something goes wrong in the actual authentification. Altough im not receiving any error either.

Thanks in advance for the help.

If you haven’t already, I would enable AutoFlush in your writer or manually Flush() after each write. I remember having an issue similar to this in the past before I switched to using a raw Socket and a NetworkStream. Making sure the writer flushes all buffered data to the underlying stream might fix your issue. It has for me in the past when using StreamWriter.

1 Like

I know this is a little off topic, but what language is that? Looks like java, but I am not sure.

To help, it looks like everything is in order. PASS first with the included oauth:token and then the NICK username.

Can I ask how you are generating your token? Are you using the Twitch OAuth Token Generator for it? Maybe the token is invalid and you aren’t getting the errors. You should use the hook before logging into IRC anyways per the Twitch API TOS. If you can’t do that, then telnet into and run through it manually to see what errors you get.

Thanks for the help guys, the issue has been resolved by adding some extra flushes like @Six suggested, also rewriting it with a plain networkstream instead of writer and reader did the trick aswell. @psilocide That is c# and the token was generated with the twitch api.


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