Exemple #1
0
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)
Exemple #2
0
def getResponse(mySocket):

    # wait for server responses...
    while True:
        try:
            retBuffer = mySocket.recv(1024)
        except:

            # close the client if the connection is down
            print "ERROR: connection down"
            sys.exit()

        if len(retBuffer) != 0:

            # parse the buffer string into xml format
            xml = ET.fromstring(retBuffer)

            # only allow correct version numbers and checksums
            if val.validate(xml):

                # send packet to correct handler
                try:
                    opcode = int(xml.find("status").text)
                    opcodes[opcode](mySocket, xml)
                except KeyError:
                    break

            break
        return
Exemple #3
0
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)
Exemple #4
0
def getResponse(mySocket):

    # wait for server responses...
    while True:
        try:
            retBuffer = mySocket.recv(1024)
        except:

            # close the client if the connection is down
            print "ERROR: connection down"
            sys.exit()

        if len(retBuffer) != 0:

            # parse the buffer string into xml format
            xml = ET.fromstring(retBuffer)

            # only allow correct version numbers and checksums
            if val.validate(xml):

                # send packet to correct handler
                try:
                    opcode = int(xml.find('status').text)
                    opcodes[opcode](mySocket, xml)
                except KeyError:
                    break

            break
        return