def start(): #Получаем ip,port ip, port = create_ip_port(type='client') # Открываем сокет new_socket = socket(AF_INET, SOCK_STREAM) new_socket.connect((ip, port)) user_name = input('Enter username: '******'You are in chat, status - {output["status"]}') else: raise Exception('Error connect') sender = Thread(target=sender_msg, kwargs={ 'transport': new_socket, 'account_name': user_name }) sender.start() writer = Thread(target=writer_msg, kwargs={'transport': new_socket}) writer.start()
def recv(self, pack, stats, ai_setting): self.image = pygame.image.load('images/router_green.png') import function as f des = pack['des'] # 从包中提取目的地址 next = self.form[des][1] # 从路由表中查找下一跳地址 f.send(pack, next, stats, ai_setting) # 转发给下一跳 f.change_line_color(self.name, next, stats, ai_setting)
def input(self, msg, stats, ai_setting): import function as f data = msg if self.name == 'Alice': pack = self.package(data, 'Bob') f.send(pack, 'D', stats, ai_setting) elif self.name == 'Bob': pack = self.package(data, 'Alice') f.send(pack, 'F', stats, ai_setting)
def mail_send(request): """ 邮件发送 :param request: :return: """ res = function.send(request) return render_json(res)
def start_server(): ip,port = create_ip_port(type='client') listen_socket = socket(AF_INET, SOCK_STREAM) listen_socket.bind((ip, port)) listen_socket.listen(CONFIGS.CONFIG_PROJECT['DEFAULT_CONF'].get('MAX_CONNECTIONS')) listen_socket.settimeout(0.3) client_list = [] while True: try: client, addr = listen_socket.accept() client_list.append(client) except OSError: pass read_clients, write_clients, error,user_messages = [],[],[],[] try: read_clients, write_clients, error = select.select(client_list, client_list, [], 0) except: pass if read_clients: for read_user_socket in read_clients: message = get_message_from_server(read_user_socket) if message['action'] == 'presence': response = check_message_on_server(message) try: send(read_user_socket, response) except: read_clients.remove(read_user_socket) pass if message['action'] == 'msg': user_messages.append(message) if user_messages and write_clients: for message in user_messages: for waiting_user in write_clients: send(waiting_user, message) user_messages.remove(message)
def regist_rand(): reg = {} phone = request.args.get('phone') if not re.match(r"^1[356789]\d{9}$", phone): reg['err'] = 1 #手机号不合法 else: reponse_phone = function.check_phone_exits(phone) if reponse_phone == 0: taatic = function.rand() taatic = str(taatic) session[phone] = taatic print(phone, taatic, 'asdsa') reg['err'] = function.send(phone, taatic) else: reg['err'] = 2 #手机号已注册 return jsonify(reg)
def jieshou(): if request.method == "POST": #从session获取数据判断是否需要重新查询(查一次就要2秒) old_date = session.get('date') old_datatype = session.get('datatype') #从前端获取数据 date = request.form['riqi[0][value]'].encode('utf-8') after = request.form['button'].encode('utf-8') after = int(after) #有没有点上一/下一时次 if (after != 0): date = function.change_date(date, after) datatype = request.form['riqi[1][value]'].encode('utf-8') datatype = find_datatype(datatype) if old_date != date or old_datatype != datatype: session['datatype'] = datatype session['date'] = date try: recv, indb, send = configure.aService().get_stat_info( datatype, date) session['recv'] = recv session['indb'] = indb session['send'] = send #print session except Exception: #错误,无内容 return render_template('jieshou.html') if after != 3: recv = session.get('recv') indb = session.get('indb') send = session.get('send') relation = configure.aService().get_area_info() #print('zheli3') #接收 jieshou, recv_advan, recv_intime, recv_later, recv_laterlost, recv_lost = function.recv( ).intime_perc(recv, relation) jieshou = rearrange(jieshou) recv_advan = rearrange(recv_advan) recv_intime = rearrange(recv_intime) recv_later = rearrange(recv_later) recv_laterlost = rearrange(recv_laterlost) recv_lost = rearrange(recv_lost) area = [i.decode('utf-8') for i in jieshou.keys()] jieshoulv = [i for i in jieshou.values()] jieshou_tiqian = [i for i in recv_advan.values()] jieshou_zhunshi = [i for i in recv_intime.values()] jieshou_yuxian = [i for i in recv_later.values()] jieshou_chaoshi = [i for i in recv_laterlost.values()] jieshou_weidao = [i for i in recv_lost.values()] area.append('江西省') jieshou_tiqian = find_sum(jieshou_tiqian) jieshou_zhunshi = find_sum(jieshou_zhunshi) jieshou_yuxian = find_sum(jieshou_yuxian) jieshou_chaoshi = find_sum(jieshou_chaoshi) jieshou_weidao = find_sum(jieshou_weidao) #入库 min1, min2, min3, min5, min10, minmax, before = function.indb( ).indb_data(indb, relation) min1 = rearrange(min1) min2 = rearrange(min2) min3 = rearrange(min3) min5 = rearrange(min5) min10 = rearrange(min10) minmax = rearrange(minmax) before = rearrange(before) min_1 = [i for i in min1.values()] min_2 = [i for i in min2.values()] min_3 = [i for i in min3.values()] min_5 = [i for i in min5.values()] min_10 = [i for i in min10.values()] min_max = [i for i in minmax.values()] tiqianruku = [i for i in before.values()] min_1 = find_sum(min_1) min_2 = find_sum(min_2) min_3 = find_sum(min_3) min_5 = find_sum(min_5) min_10 = find_sum(min_10) min_max = find_sum(min_max) tiqianruku = find_sum(tiqianruku) #发送 send_before, send_intime, send_later, send_laterlost, send_lost = function.send( ).send_data(send, relation) send_before = rearrange(send_before) send_intime = rearrange(send_intime) send_later = rearrange(send_later) send_laterlost = rearrange(send_laterlost) send_lost = rearrange(send_lost) fasong_tiqian = [i for i in send_before.values()] fasong_zhunshi = [i for i in send_intime.values()] fasong_yuxian = [i for i in send_later.values()] fasong_chaoshi = [i for i in send_laterlost.values()] fasong_weidao = [i for i in send_lost.values()] fasong_tiqian = find_sum(fasong_tiqian) fasong_zhunshi = find_sum(fasong_zhunshi) fasong_yuxian = find_sum(fasong_yuxian) fasong_chaoshi = find_sum(fasong_chaoshi) fasong_weidao = find_sum(fasong_weidao) title = return_title(date) return jsonify( shuju_type='0', riqi=date, title=title, area=area, jieshoulv=jieshoulv, jieshou_tiqian=jieshou_tiqian, jieshou_zhunshi=jieshou_zhunshi, jieshou_yuxian=jieshou_yuxian, jieshou_chaoshi=jieshou_chaoshi, jieshou_weidao=jieshou_weidao, #接收 min_1=min_1, min_2=min_2, min_3=min_3, min_5=min_5, min_10=min_10, min_max=min_max, tiqianruku=tiqianruku, #入库 fasong_tiqian=fasong_tiqian, fasong_zhunshi=fasong_zhunshi, fasong_yuxian=fasong_yuxian, fasong_chaoshi=fasong_chaoshi, fasong_weidao=fasong_weidao, #发送 ) elif after == 3: recv = session.get('recv') indb = session.get('indb') send = session.get('send') city = request.form['city'].encode('utf-8') city_relation = configure.aService().translate() city_adcd = getkey(city_relation, city)[0] town_relation = configure.aService().get_area_info() town_adcd = getkey(town_relation, city_adcd) #print town_adcd #接收 perc, recv_advan, recv_intime, recv_later, recv_laterlost, recv_lost = function.recv( ).intime_perc(recv, town_adcd, 2) perc = rearrange(perc) recv_advan = rearrange(recv_advan) recv_intime = rearrange(recv_intime) recv_later = rearrange(recv_later) recv_laterlost = rearrange(recv_laterlost) recv_lost = rearrange(recv_lost) area = [i.decode('utf-8') for i in recv_advan.keys()] jieshoulv = [i for i in perc.values()] jieshou_tiqian = [i for i in recv_advan.values()] jieshou_zhunshi = [i for i in recv_intime.values()] jieshou_yuxian = [i for i in recv_later.values()] jieshou_chaoshi = [i for i in recv_laterlost.values()] jieshou_weidao = [i for i in recv_lost.values()] #入库 min1, min2, min3, min5, min10, minmax, before = function.indb( ).indb_data(indb, town_adcd, 2) min1 = rearrange(min1) min2 = rearrange(min2) min3 = rearrange(min3) min5 = rearrange(min5) min10 = rearrange(min10) minmax = rearrange(minmax) before = rearrange(before) min_1 = [i for i in min1.values()] min_2 = [i for i in min2.values()] min_3 = [i for i in min3.values()] min_5 = [i for i in min5.values()] min_10 = [i for i in min10.values()] min_max = [i for i in minmax.values()] tiqianruku = [i for i in before.values()] #发送 send_before, send_intime, send_later, send_laterlost, send_lost = function.send( ).send_data(send, town_adcd, 2) send_before = rearrange(send_before) send_intime = rearrange(send_intime) send_later = rearrange(send_later) send_laterlost = rearrange(send_laterlost) send_lost = rearrange(send_lost) fasong_tiqian = [i for i in send_before.values()] fasong_zhunshi = [i for i in send_intime.values()] fasong_yuxian = [i for i in send_later.values()] fasong_chaoshi = [i for i in send_laterlost.values()] fasong_weidao = [i for i in send_lost.values()] return jsonify( area=area, jieshoulv=jieshoulv, shuju_type='0', jieshou_tiqian=jieshou_tiqian, jieshou_zhunshi=jieshou_zhunshi, jieshou_yuxian=jieshou_yuxian, jieshou_chaoshi=jieshou_chaoshi, jieshou_weidao=jieshou_weidao, min_1=min_1, min_2=min_2, min_3=min_3, min_5=min_5, min_10=min_10, min_max=min_max, tiqianruku=tiqianruku, #入库 fasong_tiqian=fasong_tiqian, fasong_zhunshi=fasong_zhunshi, fasong_yuxian=fasong_yuxian, fasong_chaoshi=fasong_chaoshi, fasong_weidao=fasong_weidao, #发送 ) print('zheli3') return render_template('jieshou.html')