def _get_next_nonkeepalive_packet_of_type(s,thetype): """ Call this instead of get next header to skip keepalives and to catch server errors. """ (msgtype, msglen) = s._get_next_header(); while (msgtype == KEEPALIVE): # Get any keepalive packets out if (msglen != 0): s.disconnect(); raise ConnectionError("Received invalid keepalive packet."); (msgtype, msglen) = s._get_next_header(); if (msgtype == SRV_MSG): msg, closed = netutils.readall(s._socket,msglen); s.disconnect(); raise ConnectionError(msg); if (msgtype != thetype): # Catch all s.disconnect(); msgtype_int = netutils.ntohb(msgtype); expected_int = netutils.ntohb(thetype); raise ConnectionError("Got unexpected reply message (" + str(msgtype_int) + "), expected " + str(expected_int) + "."); return (msgtype,msglen);
#!/usr/bin/python import reatlas_client import netutils atlas = reatlas_client.REatlas("localhost",65535); atlas.connect(); atlas.build_functions(); #print(atlas.login(username="******",password="******")); #print(atlas._get_available_methods()); #print(atlas._select_current_file(filename="test")) atlas._socket.sendall(reatlas_client.BIN_REQUEST + netutils.htonll(0)); packtype = atlas._socket.recv(1); l = netutils.ntohll(atlas._socket.recv(8)); print("Type: " + str(netutils.ntohb(packtype)) + " (" + packtype + ")"); print("Length: " + str(l)); print(atlas._socket.recv(l)); atlas.disconnect();