0
它沒有顯示他由客戶端發送的文本,並且客戶端發送的消息有望顯示在文本框中,但它不是顯示。 請幫我做這個。問題基本上是如何將接收到的表單客戶端的文本顯示到服務器中的文本小部件。服務器不顯示使用Tkinter製作的文本小部件中從客戶端獲得的消息
import socket
import sys
from Tkinter import *
import tkMessageBox
HOST = '' # Symbolic name meaning all available interfaces
PORT = 40025 # Arbitrary non-privileged port
# Datagram (udp) socket
try :
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print 'Socket created'
except socket.error, msg :
print 'Failed to create socket. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
try:
s.bind((HOST, PORT))
except socket.error , msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
def talk():
#now keep talking with the client
while 1:
# receive data from client (data, addr)
d = s.recvfrom(1024)
text_area.insert(END,'Client:+'+d+'\n')
data = d[0]
addr = d[1]
if not data:
break
reply = 'OK...' + data
s.sendto(reply , addr)
text_area.insert(END,'Server:'+reply+'\n')
print 'Message[' + addr[0] + ':' + str(addr[1]) + '] - ' + data.strip()
s.blocking(0)
mainloop()
root = Tk()
frame = Frame(root)
frame.pack()
root.geometry("500x500")
text_area = Text(frame)
text_area.pack(side=BOTTOM)
talk()
root.mainloop()
s.close()
那麼這個問題的傢伙有什麼解決方案。 – user3475345