Python UDP Socket Not Receiving Data -
i attempting write udp chat system, reason listen() loop not working , can not figure out why.
import socket import json import landerdb import threading class peerchat: def __init__(self): self.sock = socket.socket(socket.af_inet, socket.sock_dgram) self.db = landerdb.connect("nodes") self.brok_ip = "" self.brok_port = 5000 def listen(self): while true: msg = self.sock.recv(1024) print msg def main(self): while true: msg = raw_input("> ") x in self.db.find("nodes", "all"): self.sock.sendto(msg, tuple(x['addr'])) def getnodes(self): self.sock.sendto("as", (self.brok_ip, self.brok_port)) open("nodes", 'wb') file: msg, addr = self.sock.recvfrom(1024) print msg file.write(msg) if __name__ == "__main__": peerchat().getnodes() threading.thread(target=peerchat().listen).start() peerchat().main()
Comments
Post a Comment