При подключении больше 16к ip адресов скрипт дает отказ:
Хотелось бы увеличить производительность скрипта и убрать дублирование серверов в списке, помогите или подскажите.
Сам код:
#Masterserver import socket,MySQLdb,ConfigParser,sqlite3,sys,thread,time def serve_forever(): host,port = cfg.get("OPTIONS","HOST"),cfg.getint("OPTIONS","PORT") s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) s.bind((host,port)) while 1: data,addr = s.recvfrom(1024) s.sendto(d,addr) def load_servers(): mode = cfg.get("OPTIONS","MODE") if mode == "FILE": file = cfg.get("FILE","FILE") srv = [i.strip("\n") for i in open(file)] elif mode == "MYSQL": host,name,user,password,table = cfg.get("MYSQL","HOST"),cfg.get("MYSQL","NAME"),cfg.get("MYSQL","USER"),cfg.get("MYSQL","PASSWORD"),cfg.get("MYSQL","TABLE") db = MySQLdb.connect(host=host,user=user,passwd=password,db=name) c = db.cursor() c.execute("SELECT * FROM %s"%table) srv = [i[0] for i in c.fetchall()] elif mode == "SQLITE": name = cfg.get("SQLITE","FILE") db = sqlite3.connect(name) c = db.cursor() c.execute("SELECT * FROM %s"%table) srv = [i[0] for i in c.fetchall()] global d _d = [0xFF,0xFF,0xFF,0xFF,0x66,0x0A] for i in srv: ip,port = i.split(":") ip = [int(j) for j in ip.split(".")] port = int(port) port = [port>>8&0xFF,port&0xFF] map(_d.append,ip) map(_d.append,port) _d += [0x00,0x00,0x00,0x00,0x00,0x00] d = "".join([chr(i) for i in _d]) print "Masterserver v0.2\n\nServer list:" for i in srv: print "\t",i try: cfg = ConfigParser.ConfigParser() cfg.read("ms.cfg") refresh = cfg.getfloat("OPTIONS","REFRESH") load_servers() thread.start_new_thread(serve_forever,()) while 1: time.sleep(refresh) print "\n" load_servers() except: print sys.exc_info()[0]
Конфиг файл:
[OPTIONS]
HOST = 0.0.0.0
PORT = 27010
#MODE = FILE
MODE = MYSQL
#MODE = SQLITE
REFRESH = 10
[FILE]
FILE = servers.txt
[MYSQL]
HOST =
NAME =
USER =
PASSWORD =
TABLE =
[SQLITE]
FILE = servers.db
Автор скрипта не я а уважаемый Arsegg за которое ему спасибо.