0

I am trying to set up a multithreaded server and client, and am currently sending information wrapped in a TCP module class. I am sending the data using pickle, and have run in to a problem where attempting to access instance variables after unpickling the data leads to "Property object at 0x", instead of the instance variable. Here is the relevant server code:

data = self.clientSocket.recv(2048)
        print(data)
        message = pickle.loads(data)

        header = message.header
        self.currUser = message.user
        if header == 'user-login':
            print("[recv] New login request")
            self.userLogin()

client code:

username = input("Username: ")
    password = input("Password: ")
    message = TCPmodule().withSocket("user-login", password, self.clientSocket)
    message.user = username
    print(message.header)
    data = pickle.dumps(message)
    self.clientSocket.send(data)

Class (classmethod used and getters/setters):

def withSocket(self, header, content, socket):
    self.header = header
    self.content = content
    self.socket = socket
    self.user = ""
    self.port = 0
    return self
@property
def header(self):
    return self._header
@header.setter
def header(self,value):
    self._header = value

@property
def content(self):
    return self._content
@content.setter
def content(self,content):
    self._content = content

@property
def user(self):
    return self._user
@user.setter
def user(self,user):
    self._user = user

property object message when I print (message.header) server side

Am somewhat new to python, so I'm not sure if I'm missing something here. Thanks

chocreme
  • 1
  • 2
  • https://stackoverflow.com/a/43420503/238704 – President James K. Polk Nov 16 '21 at 14:03
  • I want to keep the connection open. I also checked the way my code runs and up until that point the number of send and recv should match up. Not sure if I'm understanding something wrong here. thanks Edit: I also checked the data being sent both serverside and clientside and it matches up.. maybe its to do with pickle? – chocreme Nov 17 '21 at 00:47
  • I'm surprised that your client doesn't say `cannot pickle 'socket' object`. – Armali Nov 18 '21 at 18:50

0 Answers0