python01-udp聊天室

import socket
def send_msg(udp_socket):
	dest_ip=input("請輸入對方IP:”)
	dest_port=int(input("請輸入對方PORT:"))
	send_data=input("請輸入要發送數據:")
	udp_socket.send(send_data.encode("utf-8"),(dest_ip,dest_port))
	
def recv_msg():
	recv_data=udp_socket.recvfrom(1024)
	print(f"{str(recv_data)}:{recv_data.decode('utf-8')}")
	print(recv_data)

def main():
	udp_socket=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
	udp_socket.bind((“”,7788))
	while True:
		send_msg(udp_socket)
		recv_msg(udp_socket)
if __name__=="__main__":
	main()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章