1 2018-5-29 16:58:13 2 明天回学校玩几天给郭星辰过生日 3 实现一个QQDemo (多线程完成,因为那部分视频损坏没看) 4 ''' 5 from threading import Thread 6 from socket import * 7 8 #1.接收数据,然后打印 9 def recvDate(): 10 while True: 11 recvInfo = udpSocket.recvfrom(1024) 12 print(">>%s:%s"%(str(recvInfo[1]),recvInfo[0])) 13 14 #2.检测键盘,发送数据 15 def sendDate(): 16 while True: 17 sendInfo = input("<<") 18 udpsocket.sendto(sendInfo.endcode("gb2312"),(destIp,destPort)) 19 20 udpSocket =None #存储对象时默认为None 21 destIp = "" 22 destPort = 0 23 def main(): 24 global udpSocket 25 global destIp 26 global destPost 27 28 # 创建udp套接字 29 destIp = input("对方的IP:") 30 destPort = input(("对方的接口")) 31 udpSocket = socket(AF_INET,SOCK_DGRAM) 32 udpSocket.bind(("",4567)) 33 34 #创建两个线程 35 tr = Thread(target=recvDate()) 36 ts = Thread(target=sendDate()) 37 38 tr.start() 39 ts.start() 40 41 tr.join() 42 ts.join() 43 44 if __name__ == "__main__": 45 main()
ps 2018-7-24 21:11:28 还好友老男孩九期多线程(并发)那部分,讲的确实很不错!所以就继续跟着老男孩走!接着学数据库