This is my server script when running it without GUI the start method only it works fine but when running the whole script and I press the start button it just freezes and not responding and nothing appears on the text window
Code:
from Tkinter import *
import socket
import sys
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.text = Text(self, width = 35, height = 5, wrap = WORD)
self.text.grid(row = 0, column = 0, columnspan = 2, sticky = W)
self.submit_button = Button(self, text='start', command = self.start)
self.submit_button.grid(row = 2, column = 0, sticky = W)
def start(self):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.text.insert(0.0, 'Server started!\n' )
self.s.bind(('',1090))
self.s.listen(10)
sc, address = self.s.accept()
self.text.insert(0.0, 'Got conn from', address )
while True:
'''msg = sc.recv(1024)
print address, ' >> ', msg
msg = raw_input('SERVER >> ')
sc.send(msg)'''
i=1
f = open('file_'+ str(i)+".txt",'wb') #open in binary
i=i+1
while (True):
l = sc.recv(1024)
while (l):
print l
f.write(l)
f.flush()
l = sc.recv(1024)
f.close()
sc.close()
#s.close()
root = Tk()
root.title("Server")
root.geometry("500x250")
app = Application(root)
root.mainloop()
Comment