0

I created the following class that I want to have a socket member within it and then want to use member functions to connect, close, send, and receive.

class Connection:
  Kon = ""
  SSLx = ""
  def Close(self):
    try:
      self.Kon.close()
      return True
    except:
      return False

  def Send(self,Message):
    try:
      self.Kon.write(Message)
      return True
    except Exception,e:
      print e
      return False


  def Recieve(self):
    try:
      Response = self.Kon.recv(10240)
      return Response
    except:
      return False

#Conenct Function Makes a SSL connection with the node
  def Connect(self,Link):
    self.SSLx = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    Ip = Link[0].replace("'",'')
    print Ip
    Port = int(Link[1])
    try:
      self.SSLx.connect((Ip,Port))
      return True
    except Exception,e:
      print "Connection Attempt Failed"
      self.Kon = socket.ssl(SSLx)
      return False

I ran the .Connect function successfully, but after that when I try the Send function it says 'str' object does not have a write member.

Any ideas on how to get this done?

BMC
  • 591
  • 3
  • 7
  • 22

1 Answers1

0

There seems to have been a small error from a debugging process I did, I had shifted one of the lines that initialized the Kon variable few lines below. The following is the corrected class.

 class Connection:
  Kon = ""
  SSLx = ""
  def Close(self):
    try:
      self.Kon.close()
      return True
    except:
      return False

  def Send(self,Message):
    try:
      self.Kon.write(Message)
      return True
    except Exception,e:
      return False


  def Recieve(self):
    try:
      Response = self.Kon.read(10240)
      return Response
    except Exception,e:
      print e
      return False

#Conenct Function Makes a SSL connection with the node
  def Connect(self,Link):
    self.SSLx = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    Ip = Link[0].replace("'",'')
    print Ip
    Port = int(Link[1])
    try:
      self.SSLx.connect((Ip,Port)) 
      self.Kon = socket.ssl(self.SSLx)
      return True
    except Exception,e:
      print e
      print "Connection Attempt Failed"
      return False
BMC
  • 591
  • 3
  • 7
  • 22