socket_ same socket to send and receive messages

# With a socket receiving the same data 

Import Socket


DEF main ():
UDP_SOCKET = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)

udp_socket.bind (( '', 8888))
the try:
DEST_IP = INPUT ( 'Enter other's IP: ')
dest_port = int (iNPUT (' enter the other port: '))
the except Exception AS E:
Print (E)

the while True:
the send_data = iNPUT (' enter the content to be transmitted: ')
UDP_SOCKET. the 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 the __name__ == '__main__ ':
main ()

Guess you like

Origin www.cnblogs.com/victorstudy/p/11224278.html