Hello,
First off, I have been working on a phone app to read back what some of my props are doing. The App can also send commands to my props. I have a tkinter form of it that works great. Even sends the command and they work. And I actually use the same code and it works great on tkinter. I am now using Kivy so I can make an App for my phone. My problem is I am getting this error when I open a listening thread. Not sure why. I can connect to the server but when I start listening for data, I get this error. There is a part where I know it might not work because it more tkinter than kivy, but I don't think that is why is it complaining. Can someone take a look at this and tell me what you think is wrong. Thank you.
You will see where I put goofy print statements all over. That is just me tracing the program.
t1 = threading.Thread(target=self.receive_message_from_server, args=(self.client_socket,))
AttributeError: 'TextAdding' object has no attribute 'client_socket'
First off, I have been working on a phone app to read back what some of my props are doing. The App can also send commands to my props. I have a tkinter form of it that works great. Even sends the command and they work. And I actually use the same code and it works great on tkinter. I am now using Kivy so I can make an App for my phone. My problem is I am getting this error when I open a listening thread. Not sure why. I can connect to the server but when I start listening for data, I get this error. There is a part where I know it might not work because it more tkinter than kivy, but I don't think that is why is it complaining. Can someone take a look at this and tell me what you think is wrong. Thank you.
You will see where I put goofy print statements all over. That is just me tracing the program.
t1 = threading.Thread(target=self.receive_message_from_server, args=(self.client_socket,))
AttributeError: 'TextAdding' object has no attribute 'client_socket'
from kivy.app import App from kivy.lang import Builder import socket import threading import time cred = 0 kv = """ Screen: BoxLayout: spacing: 10 orientation: "vertical" ScrollView: id: scroll_view always_overscroll: False BoxLayout: size_hint_y: None height: self.minimum_height orientation: 'vertical' Label: id: label size_hint: None, None size: self.texture_size BoxLayout: size_hint_y: None orientation: 'horizontal' TextInput: id: textx font_size: 25 size_hint_x: 5 size_hint_y: 0.5 boarder: (5,5,5,5) orientation: 'horizontal' Button: text: "Add Text" size_hint_y: 0.5 on_release: app.add_text() """ last_received_message = None class TextAdding(App): def __init__(self, **kwargs): super().__init__(**kwargs) self.text_counter = 0 print("hello2") self.run_connect() self.listen_for_incoming_messages_in_a_thread() def connect_client(self): time.sleep(5) counter = 1 client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.so = socket.socket(socket.AF_INET, socket.SOCK_STREAM) remote_ip = '192.168.1.102' remote_port = 10319 while counter < 100: try: client_socket.connect((remote_ip, remote_port)) # Needs to be in line with first indent. print(client_socket) break except socket.error as error: print("Connection failed") print("Attempt ", counter) counter += 1 def run_connect(self): t = threading.Thread(target=self.connect_client) t.start() def listen_for_incoming_messages_in_a_thread(self): t1 = threading.Thread(target=self.receive_message_from_server, args=(self.client_socket,)) t1.start() def receive_message_from_server(self, so): print(so) while True: buffer = so.recv(256) if not buffer: break message = buffer.decode('utf-8') print(message) # self.chat_transcript_area.insert('end', message + '\n') # self.chat_transcript_area.yview(END) if "joined" in message: user = message.split(":")[1] message = user + " has joined" self.chat_transcript_area.insert('end', message + '\n') self.chat_transcript_area.yview(END) else: self.chat_transcript_area.insert('end', message + '\n') self.chat_transcript_area.yview(END) print("jello") so.close() def build(App): print("hello") return Builder.load_string(kv) print("booger") def tammy(App): print("hello9") def add_first(self): self.root.ids.label.text += f"Please enter button \n" def add_text(self): print("hello4") print(self.root.ids.textx.text) self.root.ids.label.text += f"{self.root.ids.textx.text}\n" #self.root.ids.label.text += f"Some text {self.text_counter}\n" self.text_counter += 1 self.root.ids.scroll_view.scroll_y = 0 self.root.ids.textx.text = "" if __name__ == "__main__": print("helloJello") TextAdding().run()