def open(self, sessiondata=None): """create a UDP socket to SNMP agent""" if isinstance(sessiondata, sessionData): self.sessiondata = sessiondata if self.sessiondata: self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # self.socket = SNMPDispatcher(self._receiver) self.socket.connect((self.sessiondata.agent, self.sessiondata.port))
def connect(self): "Connect to a host on a given (SSL) port." sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.host, self.port)) realsock = sock if hasattr(sock, "_sock"): realsock = sock._sock ssl = socket.ssl(realsock, self.key_file, self.cert_file) self.sock = FakeSocket(sock, ssl)
def connect(self): """Connect to the host and port specified in __init__.""" msg = "getaddrinfo returns an empty list" for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.sock = socket.socket(af, socktype, proto) # self.sock = asyncio.SocketDispatcher() # self.sock.create_socket(af, socktype, proto) if self.debuglevel > 0: print "connect: (%s, %s)" % (self.host, self.port) self.sock.connect(sa) except socket.error, msg: if self.debuglevel > 0: print 'connect fail:', (self.host, self.port) if self.sock: self.sock.close() self.sock = None continue break
raise RuntimeError, "Plim Ip address invalid %s." %msg if self.log: self.log.write("Creating socket server for port %s.\n" %plimPort) try: sockArgs = socket.getaddrinfo(localhost, int(plimPort), socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE)[0] af, socktype, proto, canonname, sa = sockArgs except: raise RuntimeError, \ "Xoom.send_command: Failed to retrieve socket args %s." try: self.sock = socket.socket(af, socktype, proto) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) except socket.error, msg: raise RuntimeError, \ "Xoom.send_command: Failed to create socket %s." %msg try: self.sock.bind(sa) self.sock.listen(1) except socket.error, msg: raise RuntimeError, \ "Xoom.send_command: Failed to bind socket %s." %msg if self.sock is None: raise RuntimeError, \ "Xoom.send_command: Could not open socket." else: