Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5953375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:49:00+00:00 2026-05-22T17:49:00+00:00

How would i loop every 5 seconds the following code : sendSocket = socket.socket

  • 0

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()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:49:01+00:00Added an answer on May 22, 2026 at 5:49 pm

    See this question:

    How to make tkinter repond events while waiting socket data?

    You can also use after_idle

    def read_the_socket():
        sendSocket.send ( 'request posit' )
        data = sendSocket.recv( 100 )
        gui.after(5000, read_the_socket)
    
    
    gui.after_idle(read_the_socket)
    

    after_idle schedules a function the be called once the GUI isn’t busy anymore. You can also use .after(time, function) to delay for a specific amount of time before calling the function again.

    Finally, you should really maintain your connection to the server not reconnect each time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write some code that would loop though all rows of a
I have a need to run a piece of code every 120 seconds. I
So, I have the following line of code, that does a for loop and
I would like to slow down a loop so that it loops every 5
I need a for loop which would print from year 2000 to 2099. [Bindable]
How to get a counter inside xsl:for-each loop that would reflect the number of
A friend was in need of an algorithm that would let him loop through
I am creating a dynamic cursor and I would like to loop over the
When a select field is changed, I would like to loop through all of
I would like to be able to loop through all of the defined parameters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.