View Single Post
  #1  
Old 11-19-2014, 06:52 AM
Alex Miranda Alex Miranda is offline
Member
 
Join Date: Mar 2014
Posts: 21
Sending a value by Thread

Hello everyone.
I'm using socket and thread on my code and I'm trying to get a value that I have received by thread and put it on my code. My variable is global, but I can't get the result out of the thread.

def recMsg():

global msg

try:
print "Conected!!"

while True:
ip = "localhost"
buffer= 1024
port= 8080
address= (ip,porta)

UDP = socket(AF_INET,SOCK_DGRAM)
UDP.bind(address)

# Recebe mensagens
msg, address= UDP.recvfrom(buffer)

# Encerra o socket
UDP.close()

except:
print "Error"


#Start Thread
try:
thread.start_new_thread(recMsg,())
except:
print "Thread error"


# I would like to print my result here
# print msg for example

Thanks for help me !
Reply With Quote