Tkinter delay for socket data

Multi tool use
Multi tool use


Tkinter delay for socket data



I wrote a client/server application. I receive data from a server that goes out as bool type. As you know the data that I am receiving in my client is in bytes, so I decode it to string and then to integer type. Depends on a data value I want to show some information in label. The program actually does what I want but after first message It doesn't show the information. After view iterations of sent data the label turns on and change its value as I want. What is happening? If program works, why with a few first iterations a loop doesn't work properly, but later it is?


#!/usr/bin/env python
import socket
import tkinter as tk

TCP_IP = '192.168.0.15'
TCP_PORT = 62
BUFFER_SIZE = 4096
data = b''

def counter_label(label)
def count(label):
global data
data = s.recv(BUFFER_SIZE)
dane_str = data.decode("utf-8")
dane_int = int(dane_str)

if dane_int != 0:
psa=15
else:
psa = 22
label.config(text=str(psa))
label.after(1, count)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))

root = tk.Tk()

label = tk.Label(root, fg="green", font="Verdana 200 bold")
label.pack()
counter_label(label)

root.mainloop()





when you define counter_label it has a syntax error : is missing and is it the complete code I am assuming there is more to it
– Inder
Jul 2 at 13:05






In TCP, there is absolutely no connection between the chunks of data being sent, and the chunks of data being received. Your .recv() call may be reading multiple items of data, or even fractional items of data: this would be much more clear if you were actually displaying the data itself, rather than just whether or not it was zero. The basic solutions to this are to make each item the same size, to put a delimiter after each item, or to precede each item with its length so that you can read the exact number of bytes necessary.
– jasonharper
Jul 2 at 13:09


.recv()





This code is all I've got. According to what @jasonharper said I need to know what data I will receive right? I am preparing this for bigger project, right now I don't have knowledge how sent data will look. Is is good idea to make it string and then take the necessary data in the form string[10:15]?
– Arkadiusz Bialowas
Jul 2 at 13:59









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

K KMkLM0 7mK jhUBuuXndd,PAzauoZOnSS,BhmCtrk56jM0v9B33aPG wFpQCzE0Ds TDjE9iRWm YOis2tA4
C31,YfD5 ueqZhi,ileM5EyZ8Fq eewAyNjPsu9MxTHAnAeSUkU6VJHv,P 74Ao16GvUHaGF 694L

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications