Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 To inherit from serverSocket.BaseServer or not?
#1
Quote:Line 201. ...May be extended, do not override."""

This line is from serverSocket.py.BaseServer class on the prescribed line. It does NOT work keeps giving an error regarding __is_shutdown not having been defined as an attribute! It does NOT work out of the box and if it's not supposed to be overridden but can be extended then wtf-riday?? Am I interpreting that correctly? I've tried everything I can think of including calling super(). This is for a University project, I need this to function properly!


Cry Cry Cry Exclamation

Using Python 3.7.2 as that is the latest python version I can use with my software...
Quote
#2
  • Show code
  • Show error traceback, complete and unaltered
  • Wrap all with bbcode tags
Quote
#3
My code:
import socketserver as server
import atexit as exit
import select
import tkinter as tk
from socketserver import _SocketWriter as sockWrite
class RobotTCPServer(server.BaseServer):
    bufferLEN = 4096
    readable = None
    writeable = None
    errorable = None
    address_family = server.socket.AF_INET

    socket_type = server.socket.SOCK_STREAM
    def __init__(self, server_address, chandler): #'weanis'. Go Friends!
        super(type(self), chandler)
        print("Starting server...")
        self.socket = server.socket.socket(self.address_family,
                                    self.socket_type)
        self.serve_forever(0.25)
        self.readable, self.writeable, self.errorable = select.select([self.socket],[self.socket],[self.socket],  30)
        exit.register(self.onExit)
        print("...started!")
    def onExit(self):
        self.socket.shutdown(1)
        self.socket.close()

class Handler(server.BaseRequestHandler):
    timeout = 30
    rbufsize = -1
    wbufsize = 0

    # A timeout to apply to the request socket, if not None.
    timeout = None

    # Disable nagle algorithm for this socket, if True.
    # Use only when wbufsize != 0, to avoid small packets.
    disable_nagle_algorithm = False

    def handle(self):
        self.data = self.rfile.readline().strip()
        print("{} wrote to:".format(self.client_address[0]))
        print("GOT DATA=\t" + self.data)
        self.wfile.write("GOT YOUR MESSAGE.")

class Graphical(tk.Tk):
    frame = None
    def __init__(self, server):
        self.tangoBot = server
        self.frame = tk.Frame(tk.Tk(), width=256, height=128)
        self.frame.bind("<Escape>", self.key)
        self.frame.bind("<Button-1>",  self.callback)
        print("Bound!")
    def mainloop(self):
        print('looping...')        
    def key(self, event):
        print("pressed" +  repr(event.char))

    def callback(self, event):
        self.frame.focus_set()
        print("clicked at", event.x, event.y)
tup = ('127.0.0.1',65000)
robotServer = RobotTCPServer(tup, None)
gfx = Graphical(robotServer)
OUTPUT:
Quote:PS D:\ROBOTICS\controllers\project_3_controller> python .\RobotTCPServer.py
Starting server...
Traceback (most recent call last):
File ".\RobotTCPServer.py", line 63, in <module>
robotServer = RobotTCPServer(tup, None)
File ".\RobotTCPServer.py", line 20, in __init__
self.serve_forever(0.25)
File "C:\Users\Jakeeee\AppData\Local\Programs\Python\Python37\lib\socketserver.py", line 222, in serve_forever
self.__is_shut_down.clear()
AttributeError: 'RobotTCPServer' object has no attribute '_BaseServer__is_shut_down'
PS D:\ROBOTICS\controllers\project_3_controller>

HEY! Nevermind. I got it working! Thank you for your patience. Being sleep deprived produces odd effects on a person...
Quote
#4
You are welcome.
Over the years I have solved much while sleeping.
If so inclined, Please share your share your solution with the forum, so others may benefit.
Thanks
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)