0

I am creating a TCP simulator in Python, however I am getting an error message on the lines self.availableStates["CLOSED"] = Closed(self) and the next 5 lines after. Can anyone help? The code where I am receiving the error is as follows:

class TCPSimulator(StateContext, Transition):
    def __init__(self):
        self.host = "127.0.0.1"
        self.port = 5000
        self.connection_address = 0
        self.socket = None
        self.commands = []
        self.availableStates["CLOSED"] = Closed(self)
        self.availableStates["ESTABLISHED"] = Established(self)
        self.availableStates["SYNSENT"] = SynSent(self)
        self.availableStates["FINWAIT1"] = FinWait1(self)
        self.availableStates["FINWAIT2"] = FinWait2(self)
        self.availableStates["TIMEDWAIT"] = TimedWait(self)
        print ("Transitioning to Closed state!")
        self.setState("CLOSED")

1 Answer 1

3

self.availableStates is not defined before used.

Add the following line

class TCPSimulator(StateContext, Transition):
    def __init__(self):
        self.host = "127.0.0.1"
        self.port = 5000
        self.connection_address = 0
        self.socket = None
        self.commands = []
        self.availableStates = {}
        self.availableStates["CLOSED"] = Closed(self)
        self.availableStates["ESTABLISHED"] = Established(self)
        self.availableStates["SYNSENT"] = SynSent(self)
        self.availableStates["FINWAIT1"] = FinWait1(self)
        self.availableStates["FINWAIT2"] = FinWait2(self)
        self.availableStates["TIMEDWAIT"] = TimedWait(self)
        print ("Transitioning to Closed state!")
        self.setState("CLOSED")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.