(conn)
return data
Receive a message

    conn has to be the socket which receive the message

    A message has to end with the bytestring  b'\xDE\xAD\xE1\x1D'
Receive a message
Receive a message
def receive(conn):
    """Receive a message

    conn has to be the socket which receive the message

    A message has to end with the bytestring  b'\xDE\xAD\xE1\x1D'
    
    """

    ip, port = conn.getpeername()
    logging.info('Receiving a message from '+ip+':'+str(port))
    data = b''
    while True:
        try:
            received = conn.recv(16)
            if not received:
                logging.error("No data received")
                break
        except:
            raise
        if b'\xDE\xAD\xE1\x1D' in received:
            data += received[:received.find(b'\xDE\xAD\xE1\x1D')]
            break
        else:
            data += received
            if data[-4:] == b'\xDE\xAD\xE1\x1D':
                data = data[:-4]
                break
    return data
def receive ( conn ) : ip , port = conn . getpeername ( ) logging . info ( 'Receiving a message from ' + ip + ':' + str ( port ) ) data = b'' while True : try : received = conn . recv ( 16 ) if not received : logging . error ( "No data received" ) break except : raise if b'\xDE\xAD\xE1\x1D' in received : data += received [ : received . find ( b'\xDE\xAD\xE1\x1D' ) ] break else : data += received if data [ - 4 : ] == b'\xDE\xAD\xE1\x1D' : data = data [ : - 4 ] break return data