0

I've created a clientscript on my debian 11 vps and if i try to run the script i will get the BrokenPipeError: [Errno 32] Broken pipe.

I've noticed that my targetserver isn't receiving anything. The connection isn't even established i think. But if i ran the same script on my windows desktop it is working without any problems.

This is my code which runs on a windows machine but not on debian 11:

import socket
from time import sleep

class PySockAPIError(Exception): pass

dftHOSTPORT =   ("IPADRESS", 30001)
dftAUTHPW =     "STUPIDLONGPASSWORD"
dftCOMMAND =    ("IS_SERVER_UP",)

class SOCKAPI:
    def __init__(self, host = dftHOSTPORT, pwd = dftAUTHPW):
        #con-data
            self.HOSTPORT = host
        self.AUTHPW = pwd
        self.con = None
        self.CreateCon()

    def CreateCon(self):
        try:
            self.con = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
            self.con.connect(self.HOSTPORT)
            print("Connected to the Server!")
        except socket.error:
            print("TBD")

    def CloseCon(self):
        if self.con:
            self.con.close()
            print("Disconnected from the Server!")

    def Send(self, cmd = dftCOMMAND):
        try:
            #send
            CMDSEND = "\xFA%s\n" % cmd
            CMDSEND = bytes(CMDSEND, "CP1252")
            print(CMDSEND)
            self.con.send(CMDSEND)

            #receive
            recv_data = self.con.recv(1024)
            try:
                print(recv_data.decode("CP1252"))
            except:
                pass
            sleep(0.1)
        except socket.error:
            raise PySockAPIError("Socket failed, con-data maybe wrong (%s, %s, %s)"%(self.HOSTPORT[0], self.HOSTPORT[1], self.AUTHPW))
        except socket.timeout:
            print("TBD!")

if __name__ == "__main__":
    sock = SOCKAPI()
    msg = ""
    while msg != "STOP":
        msg = input("Enter a Command:")
        sock.Send(msg)
    sock.CloseCon()

Here is the output on the debain server

I've already tried to work with signal(SIGPIPE,SIG_IGN), but this just made my error disappear, but still the connection isn't registered on my targetserver. I don't know why the same script is running from windows but not from unix.

Thanks in advance

Unknown
  • 3
  • 3
  • [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) Please [edit] your question and copy&paste the output *as text* and format it as a code block. What server code do you use? Please create a [mre] using a connection to `localhost`. Make sure you *copy&paste* exactly the code you run on your system. Print a useful error message in the exception handlers, e.g. `traceback.print_exc()` – Bodo Feb 13 '23 at 16:54

0 Answers0