def main(): s = socket() s.bind(("localhost", 3030)) s.listen(1) conn, addr = s.accept() while True: #mensaje recivido incoming_data = conn.recv(1024) print("mensaje recivido en incomingdata del lado servidor" + incoming_data) if incoming_data: packet_id, message = packet.unpack(incoming_data) if packet_id == packet.MESSAGE: packet.send( conn, packet.pack( packet.MESSAGE, 'servicio') #incoming_data debe recivir servicio ) print("incomingdata del lado ddel server" + incoming_data) elif packet_id == packet.PING: packet.send(conn, packet.pack(packet.PING, "")) s.close()
def createCli(addr, connData): sd = socket.socket(type=socket.SOCK_DGRAM) if not packet.send(sd, connData, addr, packet.CONNECT): sd.close() return return sd
async def ira(program: List[int] = Query(None)): print('ira got ', program) # resp = post('http://192.168.1.66/', data=dumps({'dmx':program}), headers={'Content-Type': 'application/json'}) # if resp.status_code == 200: # return program # else: return resp.status_code return packet.send(*program)
def run(sd, conn, srv): addr = conn[1] data = packet.get(conn[0], packet.CONNECT) f = checkConnData(data) if type(f) == int: return sendErr(sd, f, addr) size = os.path.getsize(data["path"]) if not packet.send(sd, {"size": size}, addr, packet.CONNECT_ACK): return if readSend(f, sd, addr): return packet.send(sd, None, addr, packet.SHUTDOWN)
def updateRange(*v): global lastUpdate if time() - lastUpdate < .05: raise PreventUpdate return c = v[1]['rgb'] p = [v[0], c['r'], c['g'], c['b'], *v[2:]] print('updating', v, p) lastUpdate = time() return packet.send(p)
def readSend(f, sd, addr): while True: data = {} data["data"] = f.read(MAXSIZE) sendReturn = packet.send(sd, data, addr, packet.DATA) recvReturn = packet.recv(sd, packet.DATA_ACK, 3.0) if None in [sendReturn, recvReturn]: return True if len(data["data"]) != MAXSIZE: break
def main(): s = socket() s.connect(("localhost", 3030)) while True: message = raw_input("Manda algo al servidor> ") print("Justo despues de mter en el input " + message) if message.lower() == "ping": output_data = packet.pack(packet.PING, "") ticks = time() else: output_data = packet.pack(packet.MESSAGE, message[1:]) print("Mensaje del message[1:] en cliente" + output_data) #elif message.lower() == 'servicio': #output_data = packet.pack(packet.MESSAGE, message[1:]) packet.send(s, output_data) print("impresion del cliente del outData" + output_data) incoming_data = s.recv(1024) print("impresion del cliente del incoData" + incoming_data) if incoming_data: packet_id, message = packet.unpack(incoming_data) if packet_id == packet.MESSAGE: if isinstance(message, bytes): print("asasas" + message) message = message.decode("utf-8") print("Mensaje con decode" + message) #print("El servidor ha respondido: %s." % message) if message == 'servicio': import ConOpenCv pass print("Este mensaje es " + message) elif packet_id == packet.PING: ticks = (time() - ticks) / 2 print("Ping: %.2f ms." % ticks) s.close()
def recvWrite(f, sd): while True: data = packet.recv(sd, timeout=5.0) if not data: return exitStr(sd, "接收数据包失败") data, addr = data if data["type"] == packet.DATA: f.write(data["data"]) if not packet.send(sd, None, addr, packet.DATA_ACK): return exitStr(sd, "发送数据回应包失败") elif data["type"] == packet.SHUTDOWN: break return True
def ira(*args): try: print('sending osc message', args[1:]) packet.send(*args[1:]) except: print('error')
def sendErr(sd, code, addr): return packet.send(sd, {"code": code}, addr, packet.ERROR)
import packet from time import sleep from datetime import datetime LIGHTS_ON = 15 commands = [[75, 0, 0, 0, 80, 8], [125, 0, 0, 0, 190, 10], [175, 0, 0, 0, 192]] delay = 10 print('loading...') sleep(2) while True: if datetime.now().hour >= LIGHTS_ON: for cmd in commands: print('sending {}'.format(cmd)) packet.send(*cmd) sleep(delay) else: packet.send(0, 0, 0, 0) t = abs(LIGHTS_ON - datetime.now().hour) print('goodnight! See you in {} hours!'.format(t)) sleep(t * 3600)