Sending Commands via a network [Python]

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Sending Commands via a network [Python]

Post by maboroshi »

I am trying to figure out why I can't interrupt my initial command over the network.

This does not work

server:

Code: Select all


def handlechild():
    print "Got connection from", clientsock.getpeername()
    while 1:
        data = clientsock.recv(4096)
        if data == "START":
            watchos(breakloop = "nobreak")
        elif data == "END":
            watchos(breakloop = "break")
        elif data == "LOG":
            logKeystrokes()
        elif data == "ENDLOG":
            logKeystrokes.UnHook()
        if not len(data):
            break
        clientsock.sendall(data)


    clientsock.close()


The part to break from the running server.

Code: Select all


results = change_handle
        for action, files in results:
            full_filename = os.path.join(path_to_watch, files)
            theact = ACTIONS.get(action, "Unknown")
            clientsock.send("\n" + str(full_filename) + str(theact) +"\n")
            if breakloop == "break":
                clientsock.send("\n" + "Exited File Watching Program" "\n")
                break
            else:
                continue
The client

Code: Select all

def connectit(port=8888):
    host = str(entry2.get())
    global s
    s.connect((host, port))
    while True:
        data = s.recv(8024)
        if not data:
            break
        listb.insert(END, str(data))
                 
def commands():
    comm = str(entry.get())
    if comm == "START":
        s.send("START")
    if comm == "END":
        s.send("END")
    if comm == "LOG":
        s.send("LOG")
    if comm == "ENDLOG":
        s.send("ENDLOG")
I can send the initial start command but when I try to run the END command it won't accept it any ideas i know my code is weak at the moment just pieced this together fast.

*cheers

User avatar
Lundis
Distorter of Reality
Distorter of Reality
Posts: 543
Joined: 22 Aug 2008, 16:00
15
Location: Deadlock of Awesome
Contact:

Re: Sending Commands via a network [Python]

Post by Lundis »

add "print data" in the server so you can see what it is you're recieving instead of "END".

Post Reply