"""
Listen for Flex network broadcast with UDP socket on port 4992.
"""

import socket
import time

UDP_IP = ""	# INADDR_ANY

UDP_PORT = 4992

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

s.bind((UDP_IP, UDP_PORT))

data, addr = s.recvfrom(1024)

print addr [0]	# IP ADDRESS

word = ""  #force word type to nil string

for x in range(28,len(data)):

    if data[x] == " ":
        print word
	word = ""

    else:
        word += data[x]

print word

s.close()

# ******************************** open TCP socket **********************

TCP_IP = addr [0]

TCP_PORT = 4992

BUFFER_SIZE = 16384

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((TCP_IP, TCP_PORT))

time.sleep(1)	# wait 1 second for receive buffer to fill

data_tcp = s.recv(BUFFER_SIZE)
 
print "**************** TCP data:******************** "

print data_tcp

s.close()
# end of program