Forums

Help with running a python script

Hi, I'm trying to run a very simple counter that returns the number it is on every time it is accessed. I'm kind of new to python and servers. Here's the code, it keeps printing "waiting" but I just want it to listen for an incoming transmission, when accessed, it creates a thread, returns the number and closes that thread.

import thread

import traceback

CLIENTS = {} count=0

def send_counter(con) :

global count
count = (count%50000) + 1    
con.send("%s" % (count))

def conectado(con, cliente):

try :       
    send_counter(con)

except  :
    traceback.print_exc()

try :
    con.close()
    thread.exit()
except :
    pass

while True :

try :

    print("waiting")
    con, cliente = tcp.accept()

    print("----------- Incoming Transmission")
    thread.start_new_thread(conectado, tuple([con, cliente]))

except :

    pass

You can't start your own socket servers on PythonAnywhere console servers.