def handle_accept(self): pair = self.accept() if pair is not None: sock, addr = pair info_tips = 'Incoming connection from ' + repr(addr) ''' #server send msg to terminal global mysock global mysock_flag mysock = sock if mysock_flag: q = Queue.Queue() t = threading.Thread(target=server_to_ter_msg, args=(q,)) t.result_queue = q t.setDaemon(True) t.start() else: pass mysock_flag = False ''' info(info_tips) handler = EchoHandler(sock) self.current = handler.data_len self.total_recv += self.current self.counter += 1
def handle_accept(self): pair = self.accept() if pair is not None: sock, addr= pair info_tips = 'Incoming connection from ' + repr(addr) f = open('/home/pi/Desktop/TTT/server_data.txt', 'a') f.write(info_tips+str(time.time())+'\n') f.close() #server send msg to terminal global mysock global mysock_flag mysock = sock if mysock_flag: q = Queue.Queue() t = threading.Thread(target=server_to_ter_msg, args=(q,)) t.result_queue = q t.setDaemon(True) t.start() else: pass mysock_flag = False info(info_tips) handler = EchoHandler(sock) self.current = handler.data_len self.total_recv += self.current self.counter += 1
def handle_accept(self): global IS_RECV_FLAG if IS_RECV_FLAG: pair = self.accept() # 接受链接 if pair is not None: sock, addr = pair info_tips = 'Incoming connection from ' + repr(addr) #server send msg to terminal global mysock global mysock_flag mysock.append(sock) # 把链接加入到已有链接中 if mysock_flag: # 建立平台给终端发送数据的socket q = Queue.Queue() t = threading.Thread(target=server_to_ter_msg, args=(q, )) t.result_queue = q t.setDaemon(True) t.start() mysock_flag = False info(info_tips) handler = EchoHandler(sock) self.current = handler.data_len self.total_recv += self.current self.counter += 1
def handle_accept(self): pair = self.accept() if pair is not None: sock, addr = pair info_tips = 'Incoming connection from ' + repr(addr) info(info_tips) handler = EchoHandler(sock) self.current = handler.data_len self.total_recv += self.current self.counter += 1
def handle_accept(self): pair = self.accept() if pair is not None: sock, addr = pair info_tips = 'Incoming connection from ' + repr(addr) info(info_tips) self.handler = EchoHandler(sock) self.current = handler.data_len self.total_recv += self.current self.counter += 1
def handle_accept(self): pair = self.accept() if pair is not None: sock, addr = pair info_tips = 'Incoming connection from ' + repr(addr) ''' #server thread q = Queue.Queue() t = threading.Thread(target=send_iot, args=(q,)+(ser,)) t.result_queue = q t.setDaemon(True) t.start() global mysock mysock = sock mysock.send('11233'.encode('hex')) ''' info(info_tips) handler = EchoHandler(sock) self.current = handler.data_len self.total_recv += self.current self.counter += 1
from conf.settings import DB_TYPE, DB_HOST, DB_USER, DB_PASSWORD, DB_PORT, DB_NAME from visual.visual_decorator import error, info try: import MySQLdb DB_INFO = '%s://%s:%s@%s:%i/%s' % (DB_TYPE, DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME) except ImportError, msg: error(msg) info_msg = "Run 'sudo apt-get install mysql-python' to fixed this!" info(info_msg) DB_INFO = 'sqlite:///:memory:' try: from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Numeric, String, Integer, ForeignKey, Float from sqlalchemy.orm import relationships engine = create_engine(DB_INFO) Base = declarative_base() Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # For view import ... except ImportError, msg: error(msg) info_msg = "Run 'pip install sqlalchemy' to fixed this!" info(info_msg)
""" This class expect two argument,one is a request (a dicts type) the another is a template split by a "|" string """ from visual.visual_decorator import error, info from utils.check_code import check from conf.protocols import SYSTEM_CMD, SYS_ID from utils.tools import get_sharengo_check_code try: import tongue except ImportError, msg: error(msg) info_msg = "Run 'pip install tongue' to fixed this!" info(info_msg) def render(request, ruler): """ :param ruler: :type request: object """ system_cmd = SYSTEM_CMD sys_id = SYS_ID temp = [] each = ruler.split("|") each.append('sys_crc') # Auto loader the old CRC for value for occupying for item in each: # loader the data format by ruler if item in request: # if the key in the request ,and go get it!
import socket import sys from visual.visual_decorator import info, warning sys.path.append("..") # from dispatch_sample import dispatch_sample from core.dispatch import Dispatch from conf.settings import IP_PORT # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Bind the socket to the part server_address = IP_PORT info_self = 'starting up on %s port ' + str(server_address) info(info_self) sock.bind(server_address) # Calling listen() puts the socket into server mode, # and accept() waits for an incoming connection # Listen for incoming connection sock.listen(1) while True: # Wait for a connection info('waiting for a connection') connection, client_address = sock.accept() try: info_one = 'connection from ' + str(client_address) info(info_one) # Receive the data in small chunks and retransmit it