[IRC] Connecting to Twitch via IP with WinSock is unresponsive

Hello, I am trying to connect to irc.chat,twitch,tv with WinSock, yet I run into an issue. It correctly prints that it connects to the server, but it never gets a response from twitch even after entering an auth token. I go to putty and connect to the same IP my program resolves and I can log in just fine. Are you not able to use WinSock with IRC/Twitch Chat?
My code: int main(){ WSADATA wsaData; int iResult; DWORD dwError; SOCKET sock; - Pastebin.com
Output:

Unsure if related but make sure you are terminating your lines sent to the server with a CR + LF (\r\n) per the IRC spec.

You are sending your PASS and NICK separately. They need to be in one string and just do the winsock send on your new string. Plus you should store the return value of the winsock send function and check that winsock was successful in sending the data.

It is possible to use Winsock with Twitch, that is what I am using with my bot, however I seem to be stuck on Joining a channel.

You are supposed to send your PASS and NICK separately, separated by newlines in the format that george replied with.

I am now sending like this https://ghostbin.com/paste/gw3m3
still with an output of this

yet when I connect with PuTTy with the same inputs I get this

I think you’re sending the wrong stuff.
char sendstr1[] = “PASS oauth:token\r\n”;
if (!send(sock, sendstr1, sizeof(sendstr1) + 1, 0))

You should in this case be doing sizeof(sendstr1) - 1.
This is a classic c string literal. The bytes are as follows(lets just presume ascii):
PASS oauth:token\r\n\0
The sizeof will include the hidden null terminator present in an explicitly made string literal. Then you’ve added another byte off the end of the string.
The you’ve sent both that overrun byte and the null across the network. The irc servers are not expecting a null or the random byte. You send a command and you terminate it with a \r\n.

Even when using if (!send(sock, sendstr2, sizeof(sendstr2) - 1, 0)) nothing changes both strings now include a \r and \n at the end as well. I am quite stumped as to what is wrong since none of these suggestions seem to fix it.

I am unsure if it is how I am sending the line or if it is just failure to receive it. I tried sending a message the Twitch IRC said was unknown just to prompt a message from the server, I do the same on my program without the same result

Using this as a send https://ghostbin.com/paste/s5stq
I get this
Screenshot - 3d0460bbc11315421104e7bb71db7f0d - Gyazo

//edit
I also connected to the Freenode.net IRC which automatically sends a message when you connect and my program did not print it.
Screenshot - 560a4b729d5ac9ecc25829bf4571e45a - Gyazo

After re-looking at my code this morning I realize I made two errors. The first being I never assign an actual buffer size to ‘char rbuf’ which can cause issues with WinSock C++. The second error I made, which I am unsure if it really was one or not, is that I never initialized my socket.I am not sure if IRC requires an initialized socket but I’d assume so.

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