Hello!
I am having a problem with my program. I am trying to write the simplest Python 3 IRC client which just connects to a channel and receives messages sent to that channel. A lot of this is cribbed from other people on here/github and so should be mostly sensible but I get ‘[Errno 54] Connection reset by peer’ when I try to receive a message and I cannot for the life of my work out why. I have tried my credentials on an online IRC client and was able to connect just fine so I don’t think it is a problem with them.
Can anyone help? The full 26 line program is below. Many thanks!
import socket
import sys
import string
server = "irc.chat.twitch.tv"
port = 6667
channel = "{a_channel_name_all_lowercase}"
nick = "{my_name_all_lowercase}"
password = "{oauth:some_token}"
irc = socket.socket()
print("connecting to: "+ server)
irc.connect((server, port))
irc.send(bytes("PASS " + password + "\r\n", "UTF-8"))
irc.send(bytes("NICK "+ nick +"\n", "UTF-8"))
irc.send(bytes("JOIN #"+ channel +"\n", "UTF-8"))
irc.send(("PRIVMSG #" + channel + " : Hello\r\n").encode("utf-8"))
while 1:
message = irc.recv(2048).decode('utf-8')
if(message != ""):
print("Msge: " + message)
if message == "PING :tmi.twitch.tv\r\n":
s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))