【发布时间】:2017-05-30 01:58:50
【问题描述】:
我正在尝试编写一个小程序,它可以连接到 irc 通道然后发送和接收消息。我成功连接到 irc 服务器,但是我无法加入任何频道。我尝试了命令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)
感谢阅读!
【问题讨论】:
标签: python-3.x sockets irc