0

I'm trying to write a python function that sends an UDP message to a remote host and receives a reply, but I have a really hard time understaning how to do this. I've been looking at thread: Simple Python UDP Server: trouble receiving packets from clients other than localhost

I understand how to send something, but how to send AND receive in the correct sequence?

Thanks in advance.

Community
  • 1
  • 1
Xvs
  • 79
  • 2
  • 9

1 Answers1

0

Please ignore, I got it..

import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 3001
MESSAGE = "asd"

sock = socket.socket(socket.AF_INET, # Internet
                 socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))

sock.bind((UDP_IP, UDP_PORT))

while True:
    data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
    print "received message:", data
Xvs
  • 79
  • 2
  • 9