0

内部にソケットメンバーを持ち、メンバー関数を使用して接続、クローズ、送信、および受信する次のクラスを作成しました。

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

.Connect 関数を正常に実行しましたが、その後 Send 関数を実行すると、「str」オブジェクトに書き込みメンバーがないと表示されます。

これを実現する方法についてのアイデアはありますか?

4

1 に答える 1

0

私が行ったデバッグ プロセスで小さなエラーが発生したようです。Kon 変数を初期化する行の 1 つを数行下に移動しました。以下は、修正されたクラスです。

 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
于 2014-04-07T18:57:13.493 に答える