About Store Forum Documentation Contact



Post Reply 
[solved]IRC connection via TCP
Author Message
RedcrowProd Offline
Member

Post: #1
[solved]IRC connection via TCP
Hi,
This is for my own personal upcoming game
I am trying to make a connection via Socket so i can listen to IRC chat (for a Twitch integration).

My problem is that the socket TCP connection is stuck in IN_PROGRESS stage.
IRC requires login information to connect properly, and i am not sure if i am doing things in the correct order, i tried different way but to no success.

The intend here is to be able to connect to a chat room on twitch IRC, the next step will be to listen and parse all msgs, then use them as a voting tool for my game

sending returns -1

here is my integration:
Code:
class Twitch_Handler
{
   Socket TwitchSocket;
   Socket.RESULT result;
   SockAddr TwitchSAddr;
   Str username = "justinfan4445";
   Str password = "randompass";
   Str channelName = "jungroan"; //Set to the channel you want ot get chat messages from
  
   FileText data;
  
   void Create()
   {
      TwitchSAddr.setHost("irc.chat.twitch.tv", 6667);
      TwitchSocket.createTcp(TwitchSAddr);
      TwitchSocket.block(false);    
      
      result = TwitchSocket.connect(TwitchSAddr);  

      data.writeMem();
      data.putText(S+"PASS " + password+"\r \n");
      data.putText(S+"NICK " + username+"\r \n");
      data.putText(S+"USER " + username + " 8 * :" + username+"\r \n");
      data.putText(S+"JOIN #" + channelName+"\r \n");
      
      int size = TwitchSocket.send(&data, data.size());
      Gui.msgBox(S, S+"sent"+size+data.size());
      
   }
  
   void Update()
   {
      Byte data[1024];
      int received = TwitchSocket.receive(data, 1024);
      //Gui.msgBox(S, S+"recv"+received);

      //Gui.msgBox(S, S+"update..."+result);
      bool failed = TwitchSocket.connectFailed();
      if(!TwitchSocket.is() || result==Socket.FAILED || failed)Create();
   }
  
   void DrawDebug()
   {

   }
}
Twitch_Handler Twitch;
(This post was last modified: 03-06-2023 05:17 PM by RedcrowProd.)
03-03-2023 09:28 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: IRC connection via TCP
this is wrong:
FileText data;
TwitchSocket.send(&data, data.size());

please use
Str8 data;
data+="..";
TwitchSocket.send(data(), data.length());

also this:
"\r \n"
probably should be replaced with this:
"\r\n"
03-04-2023 04:30 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #3
RE: IRC connection via TCP
thanks i have updated with your feedback but this int size = TwitchSocket.send(data(), data.length()); still shows as -1.
any reason why it wouldnt send if the connection status is pending ?
Code:
class Twitch_Handler
{
   Socket TwitchSocket;
   Socket.RESULT result;
   SockAddr TwitchSAddr;
   Str username = "justinfan4445";
   Str password = "randompass";
   Str channelName = "jungroan"; //Set to the channel you want ot get chat messages from
  
   void Create()
   {
      TwitchSAddr.setHost("irc.chat.twitch.tv", 6667);
      bool created = TwitchSocket.createTcp(TwitchSAddr);
      TwitchSocket.block(false);    
      
      result = TwitchSocket.connect(TwitchSAddr);  

      Str8 data;
      data +=S+"CAP REQ :twitch.tv/tags twitch.tv/commands"+"\r\n";
      data +=S+"PASS " + password+"\r\n";
      data +=S+"NICK " + username+"\r\n";
      data +=S+"USER " + username + " 8 * :" + username+"\r\n";
      data +=S+"JOIN #" + channelName+"\r\n";

      
      int size = TwitchSocket.send(data(), data.length());
      Gui.msgBox(S, S+"sent"+size+"/ of "+data.length()+" tcp created"+created+" result "+result);
      
      TwitchSocket.flush(0);
      
   }
  
   void Update()
   {
      Byte data[1024];
      int received = TwitchSocket.receive(data, 1024);
      
      Gui.msgBox(S, S+"result "+result);
      
      bool failed = TwitchSocket.connectFailed();
      if(!TwitchSocket.is() || result==Socket.FAILED || failed)Create();
   }
  
   void DrawDebug()
   {

   }
}
Twitch_Handler Twitch;
(This post was last modified: 03-04-2023 04:57 AM by RedcrowProd.)
03-04-2023 04:56 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: IRC connection via TCP
it appears you don't wait for connection to connect before sending data
03-04-2023 05:17 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #5
RE: IRC connection via TCP
moving result = TwitchSocket.connect(TwitchSAddr); after does not work either

i dont believe i need to bind to a SockAddr ?

returns the size of sent data (-1 on fail) -> atm returns -1 with connect before or after
(This post was last modified: 03-04-2023 05:34 AM by RedcrowProd.)
03-04-2023 05:24 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: IRC connection via TCP
my last post had a typo
want -> wait
you have to wait for connection to connect first
Check for any Socket.wait
03-04-2023 06:25 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #7
RE: IRC connection via TCP
yes i made a waiting logic in the update to avoid stalling the app, and it worked well ! thanks. i got the twitch IRC channel listener working smile
(This post was last modified: 03-06-2023 05:16 PM by RedcrowProd.)
03-06-2023 05:16 PM
Find all posts by this user Quote this message in a reply
Post Reply