Example #1
0
 def _get_next_header(s):
      """ Read the header of the next message from the server.
      Assumes that the next data sent from the server is a completely
      new message. """
      (header, closed) = netutils.readall(s._socket,9);
      if (closed):
           s.disconnect();
           if (len(header) > 0):
                raise ConnectionError("Connection closed when reading message.");
           else:
                raise ConnectionError("Trying to read from closed connection.");
      msgtype, msglen = struct.unpack("!BQ", header);
      msgtype = netutils.htonb(msgtype);
      
      return (msgtype, msglen);
Example #2
0
#!/usr/bin/python2

from __future__ import print_function
import socket
import json
import argparse
import struct
import time
import os,sys
import netutils
import ConfigParser
import numpy


JSON_MSG = netutils.htonb(74); # Ascii 'J'
SRV_MSG = netutils.htonb(83); # Ascii 'S'
BIN_REQUEST = netutils.htonb(66); # Ascii 'B'
BIN_FILE = netutils.htonb(70); # Ascii 'F'
BIN_ACK = netutils.htonb(65); # Ascii 'A'
KEEPALIVE = netutils.htonb(75); # Ascii 'K'


## General error for the RE atlas
class REatlasError(Exception):
     pass;

# Connection specific error with the atlas.
# When this is raised, the connection is always closed afterwards.
class ConnectionError(Exception):
     pass;