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'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
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() |