Chat messages (update loop) [FIXED]

Hey everyone,

I have been trying to get the chat messages back from a stream with not a lot of succes.
I kinda want an event that happens whenever someone enters a new message in the chat so I can use that. This is what I have right now:

class TwitchConnection
{
    private TcpClient _tcpClient;
    private StreamReader _inputStream;
    private StreamWriter _outputStream;

    public TwitchConnection(string userName, string password)
    {
        _tcpClient = new TcpClient("irc.chat.twitch.tv", 6667);
        _inputStream = new StreamReader(_tcpClient.GetStream());
        _outputStream = new StreamWriter(_tcpClient.GetStream());

        _outputStream.WriteLine("PASS " + password);
        _outputStream.WriteLine("NICK " + userName);
        _outputStream.Flush();
    }

    public string ReadLine()
    {
        return _inputStream.ReadLine();
    }
}

I tried creating my own “update loop” like this but it seems like it gets into an infinite loop somewhere.

public MainForm()
    {
        InitializeComponent();

        _reading = false;
        LblQuestion.Text = "";

        Application.Idle += delegate { Invalidate(); UpdateLoop(); };
    }

private void UpdateLoop()
        {
            if (_connection != null && _reading)
            {
                Console.WriteLine(_connection.ReadLine());
            }
        }

I am not experienced at all with the twitch api and that’s why I came here (Not a lot of youtube vids about this subject)\

Thanks in advance,
Patrick

Chat messages end in \r\n, which isn’t the only line terminator WriteLine can use. You should make sure it’s using the correct one either by defining it yourself or explicitly every time using Write.

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