Example #1
0
 def print(self, msg, ending="\n"):
     self.conn.sendall(b'{"op":"print"}')
     basic.recvall(self.conn)
     msg = str(msg).encode(self.encoding) + str(ending).encode(
         self.encoding)
     self.conn.sendall(msg)
     basic.recvall(self.conn)
Example #2
0
    def recvFile(self, data):
        self.sock.sendall(b"{}")
        name = basic.recvall(self.sock).decode(self.encoding)
        self.sock.sendall(b"{}")
        conntend = basic.recvall(self.sock)
        self.sock.sendall(b"{}")

        with open(name, "wb") as f:
            f.write(conntend)
Example #3
0
    def sendFile(self, data):
        self.sock.sendall(b"{}")
        name = basic.recvall(self.sock).decode(self.encoding)

        try:
            with open(name, "rb") as f:
                c = f.read()
        except:
            c = b""

        self.sock.sendall(c)
Example #4
0
def handler(conn,addr,args):
    try:
        msg = basic.recvall(conn).decode("utf-8")
        if len(msg) > 0:
            address = " {}:{} ".format(addr[0], addr[1])
            logging.debug("="*8 + address + "="*(size[0]-8-len(address)))
            logging.debug(msg)
            logging.debug(datetime.datetime.now())
        conn.sendall(b"HTTP/1.0 404 Not Found\r\nContent-Encoding: utf-8\r\nAccess-Control-Allow-Headers: *\r\nContent-Type: text/html\r\nContent-Length: 0\r\n\r\n")
    except Exception as E:
        logging.debug("="*8 + address + "="*(size[0]-8-len(address)))
        logging.error(str(E))
Example #5
0
 def sendFile(self, name, data: bytes):
     self.conn.sendall(b'{"op":"recvFile"}')
     basic.recvall(self.conn)
     self.conn.sendall(str(name).encode(self.encoding))
     basic.recvall(self.conn)
     self.conn.sendall(data)
     basic.recvall(self.conn)
Example #6
0
    def start(self):
        try:
            while True:
                op = json.loads(basic.recvall(self.sock).decode("utf-8"))
                if "op" in op.keys() and op["op"] == "exit":
                    self.sock.sendall(b"{}")
                    return

                if "op" in op.keys() and op["op"] in self.operations.keys():
                    self.operations[op["op"]](op)

        except KeyboardInterrupt:
            return self.sock
Example #7
0
 def input(self, data):
     self.sock.sendall(b"{}")
     start = basic.recvall(self.sock).decode(self.encoding)
     self.sock.sendall(input(start).encode(self.encoding))
Example #8
0
 def print(self, data):
     self.sock.sendall(b"{}")
     sys.stdout.write(basic.recvall(self.sock).decode(self.encoding))
     self.sock.sendall(b"{}")
Example #9
0
 def exit(self):
     self.conn.sendall(b'{"op":"exit"}')
     basic.recvall(self.conn)
Example #10
0
 def recvFile(self, name):
     self.conn.sendall(b'{"op":"sendFile"}')
     basic.recvall(self.conn)
     self.conn.sendall(str(name).encode(self.encoding))
     return basic.recvall(self.conn)
Example #11
0
 def input(self, start):
     self.conn.sendall(b'{"op":"input"}')
     basic.recvall(self.conn)
     msg = str(start).encode(self.encoding)
     self.conn.sendall(msg)
     return basic.recvall(self.conn).decode(self.encoding)