def listening(self, queue): assert isinstance(queue, Queue.Queue) inputs = [self.server] while inputs: rs, ws, es = select.select(inputs, [], [], 5) for r in rs: if r is self.server: clientsock, clientaddr = r.accept() inputs.append(clientsock) else: data = r.recv(2048) #if not data: #inputs.remove(r) if data: print data, 'Incomming from ', clientaddr queue.put(data) data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y%m%d') #data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) data_operator = GPRS_data_operator( os.path.join(data_config['data_dir'], data_time + '.dat')) data_operator.write_data(data) else: print 'no data comming, closing' inputs.remove(r)
def send_mail(self): send_date = self.pre_date.strftime('%Y%m%d') temp_config = GPRS_data_operator.read_config() try : GPRS_SendEmail(sub='Data of '+send_date, content='There is auto-sender of GPRS_receiver', att=os.path.join(temp_config['data_dir'],send_date+'.dat')) print send_mail,': send email ok!' except Exception as msg: print 'send email faild,',msg
def handle_read(self): data =self.recv(1024) if data : print data GPRS_handler.current_data = data GPRS_handler.current_flag = time.strftime('%Y-%m-%d:%H:%M%S') data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y-%m-%d') data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) data_operator.write_data(data)
def send_mail(self): send_date = self.pre_date.strftime('%Y%m%d') temp_config = GPRS_data_operator.read_config() try: GPRS_SendEmail(sub='Data of ' + send_date, content='There is auto-sender of GPRS_receiver', att=os.path.join(temp_config['data_dir'], send_date + '.dat')) print send_mail, ': send email ok!' except Exception as msg: print 'send email faild,', msg
def handle_read(self): data = self.recv(1024) if data: print data GPRS_handler.current_data = data GPRS_handler.current_flag = time.strftime('%Y-%m-%d:%H:%M%S') data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y-%m-%d') data_operator = GPRS_data_operator( os.path.join(data_config['data_dir'], data_time + '.txt')) data_operator.write_data(data)
def recv(self,queue): while True: try : data = self.server.recv(0xfff) print time.strftime('%Y-%m-%d %h:%M:%s'),data,'Incomming from '#,clientaddr queue.put(data) data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y-%m-%d') data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) data_operator.write_data(data) except Exception,e: print e
def read_text(self): data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y%m%d') data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.dat')) self.ip_var.set(data_config['ip']) self.port_var.set(data_config['port']) self.directory_var.set(data_config['data_dir']) data = data_operator.read_data() #print data self.receiver_data.insert(END,''.join(data)) #data_operator.write_data(data) self.pre_date = datetime.now()
def read_text(self): data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y%m%d') data_operator = GPRS_data_operator( os.path.join(data_config['data_dir'], data_time + '.dat')) self.ip_var.set(data_config['ip']) self.port_var.set(data_config['port']) self.directory_var.set(data_config['data_dir']) data = data_operator.read_data() #print data self.receiver_data.insert(END, ''.join(data)) #data_operator.write_data(data) self.pre_date = datetime.now()
def recv(self, queue): while True: try: data = self.server.recv(0xfff) print time.strftime( '%Y-%m-%d %h:%M:%s'), data, 'Incomming from ' #,clientaddr queue.put(data) data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y-%m-%d') data_operator = GPRS_data_operator( os.path.join(data_config['data_dir'], data_time + '.dat')) data_operator.write_data(data) except Exception, e: print e
def listening(self,queue): assert isinstance(queue,Queue.Queue) #inputs = [self.server] while True: #clientsock,clientaddr = self.server.accept() #rs,ws,es = select.select(inputs,[],[],5) #for r in rs: # if r is self.server: # clientsock,clientaddr = r.accept() # inputs.append(clientsock) # else : # data = r.recv(0xfff) # #if not data: # #inputs.remove(r) # if data : # print data,'Incomming from ',clientaddr # queue.put(data) # data_config = GPRS_data_operator.read_config() # data_time = time.strftime('%Y%m%d') # data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) # data_operator.write_data(data) conn,addr = self.server.accept() print addr,'is connected!' try : data = conn.recv(2048) if len(data)>0: print data,'Incomming from ',addr data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y%m%d') data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) data_operator.write_data(data) queue.put(data) else : conn.shutdown(socket.SHUT_RDWR) conn.close() except Exception as msg: conn.shutdown(socket.SHUT_RDWR) conn.close() print msg