def handler(conn, lock, myData): # keep track of erroneous opcodes second_attempt = 0 while True: # retrieve header try: netbuffer = conn.recv(1024) except: # close the thread if the connection is down thread.exit() # if we receive a message... if len(netbuffer) >= 6: # parse the xml xml = ET.fromstring(netbuffer) # only allow correct version numbers and buffers that are of the appropriate length if val.validate(xml): # try to send packet to correct handler try: opcode = int(xml.find("opcode").text) opcodes[opcode](conn, xml, myData, lock) # catch unhandled opcodes except KeyError: if second_attempt: # disconnect the client myServerSend.end_session_success(conn) conn.close() return else: # send incorrect opcode message second_attempt = 1 unknown_opcode(conn)
def handler(conn, lock, myData): #keep track of erroneous opcodes second_attempt = 0 while True: #retrieve header try: netbuffer = conn.recv(1024) except: #close the thread if the connection is down thread.exit() #if we receive a message... if len(netbuffer) >= 6: # parse the xml xml = ET.fromstring(netbuffer) #only allow correct version numbers and buffers that are of the appropriate length if val.validate(xml): #try to send packet to correct handler try: opcode = int(xml.find('opcode').text) opcodes[opcode](conn, xml, myData, lock) #catch unhandled opcodes except KeyError: if (second_attempt): #disconnect the client myServerSend.end_session_success(conn) conn.close() return else: #send incorrect opcode message second_attempt = 1 unknown_opcode(conn)
def handler(conn, lock, myData): #keep track of erroneous opcodes second_attempt = 0 while True: #retrieve header try: netbuffer = conn.recv(1024) except: #close the thread if the connection is down thread.exit() #unpack message... request = sxml.parse_xml(netbuffer) error = sxml.validate_request(request) if error == NO_ERROR: opcode = request.find("body").find("op_code").text opcodes[opcode](conn, request, myData, lock) elif error == UNKNOWN_OPCODE: if (second_attempt): #disconnect the client myServerSend.end_session_success(conn) conn.close() return else: #send incorrect opcode message second_attempt = 1 unknown_opcode(conn)
def handler(conn,lock, myData): #keep track of erroneous opcodes second_attempt = 0 while True: #retrieve header try: netbuffer = conn.recv( 4096 ) except: #close the thread if the connection is down thread.exit() #if we receive a message... if len(netbuffer) >= HEADER_LENGTH: #unpack it... header = struct.unpack('!IQ',netbuffer[0:HEADER_LENGTH]) #only allow correct version numbers and buffers that are of the appropriate length if header[0] == version and len(netbuffer) == header[1] + HEADER_LENGTH: json_data = json.loads(netbuffer[HEADER_LENGTH:]) #try to send packet to correct handler try: opcodes[json_data['operation']](conn,json_data,myData,lock) #catch unhandled opcodes except KeyError: if(second_attempt): #disconnect the client myServerSend.end_session_success(conn) conn.close() return else: #send incorrect opcode message second_attempt = 1 unknown_opcode(conn)
def handler(conn,lock, myData): #keep track of erroneous opcodes second_attempt = 0 while True: #retrieve header try: netbuffer = conn.recv(1024) except: #close the thread if the connection is down thread.exit() #unpack message... request = sxml.parse_xml(netbuffer) error = sxml.validate_request(request) if error == NO_ERROR: opcode = request.find("body").find("op_code").text opcodes[opcode](conn, request, myData, lock) elif error == UNKNOWN_OPCODE: if(second_attempt): #disconnect the client myServerSend.end_session_success(conn) conn.close() return else: #send incorrect opcode message second_attempt = 1 unknown_opcode(conn)
def handler(conn, lock, myData): #keep track of erroneous opcodes second_attempt = 0 while True: #retrieve header try: netbuffer = conn.recv(1024) except: #close the thread if the connection is down thread.exit() #if we receive a message... if len(netbuffer) >= 4: # Get the GPB message length length = struct.unpack('!I', netbuffer[0:4])[0] if len(netbuffer) == 4: # Only received the length so far netbuffer += mySocket.recv(1024) #only allow correct version numbers and buffers that are of the appropriate length if (len(netbuffer) == (length + 4)): # Populate the message with the data received message = messages_pb2.ClientRequest() message.ParseFromString(netbuffer[4:4 + length]) if (message.version == version) and verify_checksum(message): opcode = message.opcode #try to send packet to correct handler try: opcodes[opcode](conn, message, myData, lock) #catch unhandled opcodes except KeyError: if (second_attempt): #disconnect the client myServerSend.end_session_success(conn) conn.close() return else: #send incorrect opcode message second_attempt = 1 unknown_opcode(conn)
def handler(conn,lock, myData): #keep track of erroneous opcodes second_attempt = 0 while True: #retrieve header try: netbuffer = conn.recv( 1024 ) except: #close the thread if the connection is down thread.exit() #if we receive a message... if len(netbuffer) >= 4: # Get the GPB message length length = struct.unpack('!I',netbuffer[0:4])[0] if len(netbuffer) == 4: # Only received the length so far netbuffer += mySocket.recv( 1024 ) #only allow correct version numbers and buffers that are of the appropriate length if (len(netbuffer) == (length + 4)): # Populate the message with the data received message = messages_pb2.ClientRequest() message.ParseFromString(netbuffer[4:4+length]) if (message.version== version) and verify_checksum(message): opcode = message.opcode #try to send packet to correct handler try: opcodes[opcode](conn,message,myData,lock) #catch unhandled opcodes except KeyError: if(second_attempt): #disconnect the client myServerSend.end_session_success(conn) conn.close() return else: #send incorrect opcode message second_attempt = 1 unknown_opcode(conn)
def end_session(conn, json_data, myData, lock): end_session_success(conn) conn.close() return
def end_session(conn,json_data,myData,lock): end_session_success(conn) conn.close() return
def end_session(conn, netBuffer, myData, lock): end_session_success(conn) conn.close() return
def end_session(conn, message, myData, lock): end_session_success(conn) conn.close() return
def end_session(conn,netBuffer,myData,lock): end_session_success(conn) conn.close() return
def end_session(conn,message,myData,lock): end_session_success(conn) conn.close() return