import socket
def main():
#创建套接字
soc = socket.socket(socket.AF_INET, socket.socket_DGRAM)
#发送数据
send_msg = input('输入要发送信息')
recv_addr = ('192.168.1.1', (1314))
soc.sendto(send_msg.encode('utf-8'), recv_addr)
#接收数据
recv_msg, recv_addr = soc.recvfrom(1024)
print('接受的信息是:%s'% recv_msg[0].decode('gbk'))
#关闭套接字
soc.close()
if __name__ == '__main__':
main()
def main():
#创建套接字
soc = socket.socket(socket.AF_INET, socket.socket_DGRAM)
#发送数据
send_msg = input('输入要发送信息')
recv_addr = ('192.168.1.1', (1314))
soc.sendto(send_msg.encode('utf-8'), recv_addr)
#接收数据
recv_msg, recv_addr = soc.recvfrom(1024)
print('接受的信息是:%s'% recv_msg[0].decode('gbk'))
#关闭套接字
soc.close()
if __name__ == '__main__':
main()