Tuesday, 10 September 2013

Socket programming in python counter not working

Socket programming in python counter not working

I am making a client and a sever relation ship using python. The client
has a button in which I click the button it will connect to the server and
count the clicked button by the client.
But in my situation, the server only count once and the client button is
not working anymore. does anybody has an idea about my case? any help will
be appreciated, thanks in advance.
this is my code
client.py
import socket
from Tkinter import*
root = Tk()
root.title("ADKOO")
root.geometry("150x80")
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12340
s.connect((host, port))
def counterPlus():
s.send('sent by '+host)
app = Frame(root)
app.grid()
button1 = Button(app, text="+", width=15, command=counterPlus)
button1.grid()
root.mainloop()
server.py
import socket
s = socket.socket()
host = socket.gethostname()
port = 12340
s.bind((host, port))
s.listen(5)
pressed = 0
while True:
c, addr = s.accept()
pressed = pressed + 1
print 'Got connection from', addr
print c.recv(1024), 'pressed count', pressed
#c.close()

No comments:

Post a Comment