СЕРВЕР
#-*- coding: utf-8 -*- from socket import * from Tkinter import * root = Tk() root.title('Сервер') root.geometry("200x200+80+80") btn = Button(root,text='Отправить') btn.place(x=70,y=60) string = Entry(root,width = 10) string.place(x = 70,y = 40) HOST = '' PORT = 8000 s = socket(AF_INET, SOCK_STREAM) s.bind(('', 8000)) s.listen(1) conn, addr = s.accept() print 'Соединенно ', addr def send(event): i = True while i is True: data = conn.recv(1024) print 'Пришло ', repr(data) reply = string.get() #reply = raw_input("Ответ: ") conn.sendall(reply) ppp = Label(root,font = "Arial 11",text = reply,width =20,) ppp.place(x = 10,y =170) root.destroy() btn.bind('<ButtonRelease-1>', send) root.mainloop() conn.close()
КЛИЕНТ
# -*- coding: utf-8 -*- from socket import * from Tkinter import * root = Tk() root.title('Клиент') root.geometry("200x200+80+80") btn = Button(root,text='Отправить') btn.place(x=70,y=60) string = Entry(root,width = 10) string.place(x = 70,y = 40) HOST = '' PORT = 8000 s = socket(AF_INET, SOCK_STREAM) s.connect((HOST, PORT)) def send(event): i = True while i is True: message = string.get() #message = raw_input("Ваше сообщение: ") s.send(message) print "Ждите ответа" reply = s.recv(1024) end send(event) def otvet(event): print "Ответ: ", repr(reply) ppp = Label(root,font = "Arial 11",text = reply,width =20,) ppp.place(x = 10,y =170) root.destroy() #root.bind('<Control-z>',quit) btn.bind('<ButtonRelease-1>', send) root.mainloop() s.close()