How would i loop every 5 seconds the following code :
sendSocket = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
sendSocket.connect ( ( 'CENSORED', 1234 ) )
sendSocket.send ( 'request posit' )
data = sendSocket.recv( 100 )
chatLog.insert(END, data)
I want a client to recieve data every 5 seconds from a server, i did a while True loop (lol) and the program interface didnt even load and the server got flooded by the client.
I just want the server to update the client every 5 seconds with a variable that is stored on the server, without a user having to manually press a button.
import socket, time
from Tkinter import *
## Main Window
gui = Tk()
gui.geometry('450x350-5+40')
gui.minsize(450,350)
gui.maxsize(450,350)
userInput = StringVar()
## Main window that displays user and server input.
chatLog = Text(gui, width=60, height=15)
chatLog.pack()
## Send Packet function, main part of the script. Sends whatever the user puts in.
def sendChat():
sendSocket = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
sendSocket.connect ( ( 'nope.com', 1234 ) )
sendSocket.send ( e.get() )
data = sendSocket.recv( 100 )
chatLog.insert(END, data)
sendSocket.close()
while True:
sendSocket = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
sendSocket.connect ( ( 'nope.com', 1234 ) )
sendSocket.send ( 'request posit' )
data = sendSocket.recv( 100 )
chatLog.insert(END, data)
sendSocket.close()
time.sleep (5.0)
## Submit text button
b = Button(gui, text="Send", command=sendChat )
b.pack()
## Text entry box
e = Entry(gui, textvariable=userInput)
e.pack()
gui.mainloop()