我不知道我做错了什么。没有错误或任何东西,它只是说我没有注册。这也是一个IRC频道和网络,不需要注册缺刻使用。提前谢谢。
#I've set variables and imported stuff up here
socket.connect((host, port))
socket.recv(512)
socket.send('NICK %s' % (username))
socket.send('USER %s %s %s :%s\r\n' % (username, username, username, username))
pingPong = socket.recv(512)
print pingPong
pingPong = pingPong[5:]
print 'PONG ' + pingPong
socket.send('PONG %s\r\n' % pingPong)
print 'PONG ' + host + '\r\n'
time.sleep(5) #I even added this time.sleep() to wait for the PONG to go through.
socket.send('JOIN %s\r\n' % channel)
socket.recv(1024)
#I have a while loop that continually receives data and commands down here
输出:
PING:912E235B
PONG:912E235B
:irc.va.us.mibbit.net 451加入:您尚未注册
答案 0 :(得分:2)
您的NICK和USER命令格式错误。 NICK最后应该有一个“\ r \ n”。 USER不应该只是您的用户名4次。下面是与该irc服务器的工作连接。
import socket
host = "irc.va.us.mibbit.net"
port = 6667
username = "andrew"
channel = "luck"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
print "recv 1", s.recv(512)
s.send('NICK %s\r\n' % (username,))
s.send('USER %s 8 * :%s\r\n' % (username, username))
pingPong = s.recv(512)
print "recv 2", pingPong
pingPong = pingPong[5:]
s.send('PONG %s\r\n' % pingPong)
s.send('JOIN %s\r\n' % (channel,))
msg = s.recv(1024)
print "Message", msg