0

So I'm building this socket application, and it works just fine on my computer. But when i start server socket on another laptop, it just crashes with a invalid start byte error: How do i proper encode the program to work with all laptops

This is the error i get on : Other laptops.

My laptop.

I have tried to change the encoding, but I'm just not quite sure where i have to change it.

Class Listener:
    def __init__(self):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server_address = (socket.gethostbyname(socket.gethostname()), 10000)
        self.sock.bind(self.server_address)
        print(f"LISTENER : {str(self.server_address[0])} port {str(self.server_address[1])}")

    def listen(self):
        self.sock.listen(1)
        while True:
            print("Connection Open")
            print("     Waiting for connections")
            self.connection, self.client_address = self.sock.accept()
            try:
                print(f"Connection from {str(self.client_address)}")
                while True:
                    data = self.connection.recv(1024)
                    if data:
                        message = str(data)
                        if not "print" in message.lower():  # This just checks if the client wants to print system information from the server
                            Validate(message)  # this checks for a command the server have to do
                        else:
                            self.connection.sendall(pickle.dumps(self.computerinfomation))
                    else:
                        self.listen()
            except Exception as e:
                print(e)

I want it to work on other laptops as well, and i just cant see why it wont.

Frodon
  • 3,684
  • 1
  • 16
  • 33
  • 1
    First: edit question and use button `{}` to format code. Second: always put error message as text - and they we can copy it. – furas Apr 01 '19 at 21:14
  • 1
    you decode bytes using `utf-8` but sender may send data in different encoding - ie. latin2, iso-8859-2, etc. I checked in Google `x91` and it is probably code in `Latin1`. You can use `str(data, encoding)` to decode in different encoding but you would have to know what encoding you have to use. So sender should send this information at start or it should encode data to `utf-8` before it sends it. – furas Apr 01 '19 at 21:19

2 Answers2

1

Furas came with a solution.

I changed the

message = str(data)

to

message = str(data, encoding="utf-8")

I did the same on the client side

0

Not going to lie. I just changed the encoding = utf-16.

Example:

df = pd.read_csv(C:/folders path/untitled.csv, encoding = "utf-16")
ouflak
  • 2,458
  • 10
  • 44
  • 49