Python statefull socket programming

I have a client-server socket python script. I want to keep the state of each connection, such that i identify whether or not the client is its first connection. I unsuccessfully wrote the following code: