标签:NPU pos 网络编程 套接字 info oba main vda ==
2018-5-29 16:58:13
明天回学校玩几天给郭星辰过生日
实现一个QQDemo (多线程完成,因为那部分视频损坏没看)
‘‘‘
from threading import Thread
from socket import *
#1.接收数据,然后打印
def recvDate():
while True:
recvInfo = udpSocket.recvfrom(1024)
print(">>%s:%s"%(str(recvInfo[1]),recvInfo[0]))
#2.检测键盘,发送数据
def sendDate():
while True:
sendInfo = input("<<")
udpsocket.sendto(sendInfo.endcode("gb2312"),(destIp,destPort))
udpSocket =None #存储对象时默认为None
destIp = ""
destPort = 0
def main():
global udpSocket
global destIp
global destPost
# 创建udp套接字
destIp = input("对方的IP:")
destPort = input(("对方的接口"))
udpSocket = socket(AF_INET,SOCK_DGRAM)
udpSocket.bind(("",4567))
#创建两个线程
tr = Thread(target=recvDate())
ts = Thread(target=sendDate())
tr.start()
ts.start()
tr.join()
ts.join()
if __name__ == "__main__":
main()
标签:NPU pos 网络编程 套接字 info oba main vda ==
原文地址:https://www.cnblogs.com/zhen1996/p/9106277.html