'TCP and UDP connections (simultaneously) python3

I don't want to bother you with my long boring code so I will explain the bottom of my problem , I'm writing a Messenger program it has global chat , it has personal messaging (same chat but only addressed client will see it) and on top of this it supposed to have a simple file transfer from the server (already known files inside the server) to every client who desires this files. so my basic architecture is TCP connection based message sending and inner language

example : [Josh]<Kristine> : Hello

means : josh sends to kristine "Hello" and only she can see it

for the file transfer part I need to use UDP and notice that I have to keep my TCP connection working

example : [Josh]<>&WantsDownload& (filesPath\sendme.txt)!DownloadsPath\receiveme.txt?

so I send &WantsDownload& request via TCP the server notice and enters a function now I need to send via UDP I tried to open another socket using same port and address it didnt work and I tried to change the current TCP socket to UDP and it didn't work

would like some help guys Im really lost

Edit : small code just in case , this two are from inside each ones functions

CLIENT.PY

serverUDP = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serverUDP.bind((HOST, UDPPORT))
data = serverUDP.recv(1024)
print(data)
serverUDP.close()

SERVER.PY

serverUDP = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serverUDP.bind((HOST, UDPPORT))
print(" is now downloading")
filename = NameOfRequesterFile
file = open(filename,'rb')
file_data = file.read(1024)
print(file_data)
serverUDP.sendto(file_data,HOST)
print("File is downloaded successfully")
serverUDP.close()

edit2: I also tried to use different port for this UDP connection , the problem accures when I use th sendto command from my udp socket , and most of my errors are this: OSError: [WinError 10038] An operation was attempted on something that is not a socket During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Python310\lib\threading.py", line 1009, in _bootstrap_inner self.run() File "C:\Python310\lib\threading.py", line 946, in run self._target(*self._args, **self._kwargs)

also tried changing in client form serverUDP.recv to serverUDP.recvform and same error



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source