示例#1
0
 def connect(self, address, family, type, timeout=5.0):
     try:
         self.info("Create socket (family %s, type %s)" % (family, type))
         self.socket = socket(family, type)
         self.socket.settimeout(timeout)
         self.info("Connect to %s" % formatAddress(family, address))
         self.socket.connect(address)
     except socket_error, err:
         writeError(
             self, err,
             "Unable to connect to %s" % formatAddress(family, address))
         self.socket = None
         self.send('application_error', 'Network connection failure')
示例#2
0
 def connect(self, address, family, type, timeout=5.0):
     try:
         self.info("Create socket (family %s, type %s)" % (
             family, type))
         self.socket = socket(family, type)
         self.socket.settimeout(timeout)
         self.info("Connect to %s" % formatAddress(family, address))
         self.socket.connect(address)
     except socket_error, err:
         writeError(self, err, "Unable to connect to %s" %
             formatAddress(family, address))
         self.socket = None
         self.send('application_error', 'Network connection failure')
示例#3
0
 def bind(self, address, family=AF_INET, type=SOCK_STREAM, reuse_address=True):
     try:
         self.socket = socket(family, type)
         if reuse_address:
             self.socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
         self.family = family
         self.socket.bind(address)
         self.socket.listen(self.backlog)
         self.error("Server waiting on %s" % formatAddress(family, address))
     except socket_error, err:
         writeError(self, err, "Unable to bind on %s" %
             formatAddress(family, address))
         self.socket = None
         self.send('application_error', 'Network server bind error')
示例#4
0
 def __init__(self, session, socket, address, family):
     self.socket = socket
     self.address = address
     self.family = family
     name = "net_client:" + formatAddress(self.family, self.address, short=True)
     SessionAgent.__init__(self, session, name)
     self.tx_bytes = 0
     self.rx_bytes = 0
示例#5
0
 def __init__(self, session, server, socket, address, family):
     self.server = weakref_ref(server)
     self.socket = socket
     self.address = address
     self.family = family
     name = "net_client:" + formatAddress(self.family, self.address, short=True)
     SessionAgent.__init__(self, session, name)
     self.tx_bytes = 0
     self.rx_bytes = 0
示例#6
0
 def bind(self,
          address,
          family=AF_INET,
          type=SOCK_STREAM,
          reuse_address=True):
     try:
         self.socket = socket(family, type)
         if reuse_address:
             self.socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
         self.family = family
         self.socket.bind(address)
         self.socket.listen(self.backlog)
         self.error("Server waiting on %s" % formatAddress(family, address))
     except socket_error, err:
         writeError(self, err,
                    "Unable to bind on %s" % formatAddress(family, address))
         self.socket = None
         self.send('application_error', 'Network server bind error')
示例#7
0
 def __repr__(self):
     return "<%s %s>" % (
         self.__class__.__name__,
         formatAddress(self.family, self.address))
示例#8
0
 def __init__(self, project, port, host=''):
     name = "tcp_server:" + formatAddress(AF_INET, (host, port), short=True)
     NetworkServer.__init__(self, project, name)
     self.host = host
     self.port = port
示例#9
0
 def __init__(self, project, port, host=''):
     name = "tcp_server:" + formatAddress(AF_INET, (host, port), short=True)
     NetworkServer.__init__(self, project, name)
     self.host = host
     self.port = port