老师,我想完成两个聊天室的实时聊天:
聊天室1的代码如下:
from socket import *
import time
#1创建套接字
udpSocket = socket(AF_INET, SOCK_DGRAM)
bindAddr = ("",7088)
udpSocket.bind(bindAddr)#绑定
data = input("请输入:")
udpSocket.sendto(data.encode("gb2312"),("",8080))
while True:
#接收对方发送的数据
recvData = udpSocket.recvfrom(1024)
print('【%s】 %s.%s' %(time.ctime(),recvData[1],recvData[0].decode("GB2312")))
a = input("请输入:")
udpSocket.sendto(a.encode('GB2312'),recvData[1])
#5关闭套接字
udpSocket.close()
聊天室2的代码如下:
from socket import *
import time
#1创建套接字
udpSocket = socket(AF_INET, SOCK_DGRAM)
bindAddr = ("",8080)
udpSocket.bind(bindAddr)#绑定
while True:
#接收对方发送的数据
recvData = udpSocket.recvfrom(1024)
print('【%s】 %s.%s' %(time.ctime(),recvData[1],recvData[0].decode("GB2312")))
a = input("请输入:")
udpSocket.sendto(a.encode('GB2312'),recvData[1])
#5关闭套接字
udpSocket.close()

始终会报错,麻烦您帮我看一下