# Receiving data with the same socket
Import Socket
class Send_msg (Object):
DEF main (Self):
UDP_SOCKET = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
udp_socket.bind (( '', 8888))
the try:
dest_ip = input ( 'enter each other ip:')
dest_port = int (iNPUT ( 'enter the other port:'))
the except Exception AS E:
Print ( 'Please input the correct ip and port')
the while True:
the send_data = input ( 'enter the content to be transmitted:')
udp_socket.sendto (send_data.encode ( 'GBK'), (DEST_IP, dest_port))
recv_data = udp_socket.recvfrom (1024)
Print (recv_data [0] .decode ( ' GBK '))
UDP_SOCKET.close()
if __name__ == '__main__':
sm = Send_msg()
sm.main()
socket_ same socket to send and receive messages _ upgrade
Guess you like
Origin www.cnblogs.com/victorstudy/p/11224282.html
Recommended
Ranking