- Edited
Attempting to connect to Twitch's IRC using the code below. I get a successful connection, but messages are not getting sent or received. I am attempting to follow various tutorials, video guides, and the Godot 4.2 docs. Currently using Godot v4.2.2 Stable Official. Thank you in advance for your time.
The code below is triggered by a button linked to the pressed_button_for_testing_in_ui
function for debugging.
extends Node
var tcp_client: StreamPeerTCP
const CLIENT_PASS = 'oauth:OAUTH_TOKEN' # Token from twitch: https://twitchapps.com/tmi/ Confirmed to work using an IRC chat
const CLIENT_NICK = 'NICK_NAME' # My user name
const CLIENT_USER = 'USER_NAME' # Attempted using user and/or nick
var old_status: int = -1
var started: bool = false
func _ready():
tcp_client = StreamPeerTCP.new()
tcp_client.set_no_delay(true)
old_status = tcp_client.STATUS_NONE
func _process(delta):
if !started:
return
tcp_client.poll()
var new_status = tcp_client.get_status()
if old_status != new_status:
if new_status == tcp_client.STATUS_NONE:
print("Disconnected")
elif new_status == tcp_client.STATUS_CONNECTING:
print("Connecting")
elif new_status == tcp_client.STATUS_CONNECTED:
print("Connected")
elif new_status == tcp_client.STATUS_ERROR:
print("Error with stream")
old_status = new_status
if new_status == tcp_client.STATUS_CONNECTED:
var available_bytes: int = tcp_client.get_available_bytes()
if available_bytes > 0:
print("Available Bytes: " + str(available_bytes))
var data: Array = tcp_client.get_partial_data(available_bytes)
if data[0] != OK:
print("Error getting data from stream: " + str(data[0]))
else:
print("Data: " + str(data[1]))
func pressed_button_for_testing_in_ui():
if old_status == tcp_client.STATUS_CONNECTED:
send_authentication()
send_data("PRIVMSG #TEST_CHANNEL MESSAGE")
send_data("Testing")
elif old_status == tcp_client.STATUS_NONE:
connect_client()
elif old_status == tcp_client.STATUS_CONNECTING:
send_authentication()
started = true
func connect_client():
print("CONNECTING CLIENT")
if tcp_client.connect_to_host("irc.chat.twitch.tv", 6697) != OK: # I have also tried with port 443
print("Error Connecting")
while tcp_client.get_status() != tcp_client.STATUS_CONNECTED:
tcp_client.poll()
func send_authentication():
print("SENDING AUTHENTICATION")
var items = [
'PASS '+ CLIENT_PASS,
'USER '+ CLIENT_USER,
]
for item in items:
send_data(item)
func print_connection():
print("get_connected_host: " + str(tcp_client.get_connected_host()))
print("get_connected_client: " + str(tcp_client.get_connected_port()))
print("get_status: " + str(tcp_client.get_status()))
func send_data(message: String):
print("Sending: " + message)
var error = tcp_client.put_data(message.to_utf8_buffer())
if error != OK:
print("Error Sending Data: " +message+" => " + str(error))