Python 3.x 无法通过python连接到IRC Hackerzvoice通道?
我正在尝试编写一个小程序,它可以连接到irc通道,然后发送和接收消息。我成功连接到irc服务器,但无法连接到任何通道。我尝试了命令Python 3.x 无法通过python连接到IRC Hackerzvoice通道?,python-3.x,sockets,irc,Python 3.x,Sockets,Irc,我正在尝试编写一个小程序,它可以连接到irc通道,然后发送和接收消息。我成功连接到irc服务器,但无法连接到任何通道。我尝试了命令JOIN#channel,但什么也没得到,服务器没有响应。 这是我的代码: try: con = socket.socket() con = socket.create_connection((client.svhost, client.svport)) print(('CONNECTING TO.. %s\r\n' % client.svhost).en
JOIN#channel
,但什么也没得到,服务器没有响应。
这是我的代码:
try:
con = socket.socket()
con = socket.create_connection((client.svhost, client.svport))
print(('CONNECTING TO.. %s\r\n' % client.svhost).encode())
con.send(('NICK %s \r\n' % client.user).encode())
con.send(('USER %s %s root-me :%s \r\n' %(client.user, client.svhost, client.user)).encode())
con.send(('JOIN %s' %client.channel).encode())
print('Joined to.. %s\r\n' %client.channel)
while True:
respond = ""
respond = con.recv(1024).strip().decode()
print(respond)
#PING - PONG
pp = respond.split()
if pp[0] == 'PING':
print(pp)
con.send(('PONG %s' %pp[1]).encode())
print(('PONG %s' %pp[1]).encode())
print('Responded')
con.send(('JOIN %s' %client.channel).encode())
except Exception as e:
print(e)
sys.exit(1)
感谢您的阅读 您在发送Pong响应时忘记添加换行符,并且在服务器识别之前添加了一个加入请求
con.send(('JOIN %s' %client.channel).encode())
print('Joined to.. %s\r\n' %client.channel)
更改:
con.send(('PONG %s' %pp[1]).encode()) # Change this line
con.send(('PONG %s\r\n' %pp[1]).encode()) # To This line
此外,您还需要在注册之前删除加入(在服务器中实际标识为用户)
您好,我试图在注册之前删除联接,但得到了相同的结果。我无法连接到需要访问的频道。您成功连接到服务器了吗?如果是这样,这只是一个连接问题,而不是以前的注册问题。我成功连接到服务器,但无法连接到通道