In my python project I have a working server. Now I am making the client side, but I keep getting the "OSError: [WinError 10038] An operation was attempted on something that is not a socket" error. I looked for solutions but most of them involved the persons code being inside of a while loop and they forgot to close the connection or something like that. My code is not like that and I have failed to find a solution. So if anyone knows the answer and the explanation to the answer please help. By the way I am following a tutorial for this.
I am getting the error on the send_message() function on line 18.
Here is my code (I have a working .kv file but if that is needed I can post it too):
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import socket
import threading
kivy.require("1.9.0")
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
class MyRoot(BoxLayout):
def __init__(self):
super(MyRoot, self).__init__()
def send_message(self):
client.send(f"{self.nickname_text.text}: {self.message_text.text}".encode("utf-8"))
def connect_to_server(self):
if self.nickname_text != "":
client.connect((self.ip_text.text, 9999))
message = client.recv(1024).decode("utf-8")
if message == "NICK":
client.send(self.nickname_text.text.encode("utf-8"))
self.send_btn.disabled = False
self.message_text.disabled = False
self.connect_btn.disabled = True
self.ip_text.disabled = True
self.make_invisible(self.connection_grid)
self.make_invisible(self.connect_btn)
thread = threading.Thread(target=self.receive)
thread.start()
def make_invisible(self, widget):
widget.visible = False
widget.size_hint_x = None
widget.size_hint_y = None
widget.height = 0
widget.width = 0
widget.text = ""
widget.opacity = 0
def receive(self):
stop = False
while not stop:
try:
message = client.recv(1024).decode("utf-8")
self.chat_text.text = message "\n"
except:
print("ERROR")
client.close()
stop = True
class WebChat(App):
def build(self):
return MyRoot()
webChat = WebChat()
webChat.run()
CodePudding user response:
I did some more debugging and it turns out the reason was because I installed the wrong version of kivy. Thanks to everyone who tried to help.