Esempio n. 1
0
    def __init__(self, ports, key=None, debug=False):
        """Initializes the receiver object with a list of sockets containing 
		one socket for each port in the ports list.

		Args:
			ports: A list of integer port number values for the receiver.
			key: A base64 format string key to be used for MAC tag generation.
				Default value = None.
			debug: A boolean value indicating debug mode. 

		Raises:
			TypeError: Error when key is not a string value, or when ports is not 
			a list of integers.
		"""

        try:
            if type(ports) != list:
                raise TypeError("invalid ports: list expected")
            elif key != None and type(key) != str:
                raise TypeError("invalid key: str expected")

            self.host, self.ports = mysocket.gethostname(), ports
            self.sock = []
            self.key = key
            self.debug = debug
            for port in ports:
                self.sock.append(mysocket())
                self.sock[-1].bind((self.host, port))
                print "Receiver socket (%s, %d) initiated" % (self.host, port)
        except:
            if debug == True:
                raise
            else:
                secureFail()
                sys.exit()
    def __init__(self, ports, key=None, debug=False):
        """Initializes the sender object with a list of sockets containing 
		one socket for each port in the ports list.

		Args:
			ports: A list of integer port number values for the sender.
			key: A base64 format string key to be used for MAC tag generation.
				Default value = None.
			debug: A boolean value indicating debug mode. 

		Raises:
			TypeError: Error when key is not a string value, or when ports is not 
			a list of integers.
		"""

        try:
            if type(ports) != list:
                raise TypeError("invalid ports: list expected")
            elif key != None and type(key) != str:
                raise TypeError("invalid key: str expected")

            self.host, self.ports = mysocket.gethostname(), ports
            self.sock = []
            self.key = key
            self.debug = debug
            for port in ports:
                self.sock.append(mysocket())
                self.sock[-1].bind((self.host, port))
                print "Sender socket (%s, %d) initiated" % (self.host, port)
        except:
            if debug == True:
                raise
            else:
                secureFail()
                sys.exit()
	def __init__(self, port, debug=False):
		"""Initializes the node object with a socket object using the port 
		number specified by the argument port.

		Args:
			port: An integer port number for the node.
			debug: A boolean value indicating debug mode. 

		Raises:
			TypeError: Error when port is not an integer.
		"""

		try:
			if type(port) not in [int, long]:
				raise TypeError("invalid port: int or long expected")

			self.host, self.port = mysocket.gethostname(), port
			self.sock = mysocket()
			self.sock.bind((self.host, self.port))
			self.share = None
			self.debug = debug
			print "Node (%s, %d) initiated" % (self.host, self.port)
		except:
			if debug == True:
				raise
			else:
				secureFail()
				sys.exit()