0

I am attempting to write a program that uses both a TCP and UDP connection. However, on the client side, attempting to create the TCP connection goes fine but the UDP connection throws windows error 10048 (Only one usage of each socket address (protocol/network address/port) is normally permitted). This is true even if they use different ports. What am I missing?

EDIT: Here is the relevant code:

 serverName = 'localhost'
 serverPort = 32000
 TCPSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 UDPSocket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
 print('socket created')
 TCPSocket.connect((serverName, serverPort))
 print('TCP connection successful')

 # the variable UDPPort is taken from a TCP message 
 #sent by the server earlier in the program
 UDPSocket.bind((serverName, UDPPort))

Edit 2: I am still having this issue, and want to bump this thread. Hopefully this works and is allowed.

Edit 3: The initial issue I believe is fixed, but I'm having a new issue as described below.

  • 5
    Please update your question with the code you have tried. – quamrana Mar 29 '20 at 20:53
  • @quamrana I have done so, sorry I neglected to do so originally. – Ythaenagor Mar 31 '20 at 17:53
  • So what is `UDPPort` when `UDPSocket.bind((serverName, UDPPort))` is executed? – quamrana Apr 06 '20 at 19:37
  • Does this [question](https://stackoverflow.com/questions/31912162/wsa-error-10048-when-binding-server-sockets) help at all? – quamrana Apr 06 '20 at 19:38
  • @quamrana `UDPPort` is set to a value determined by the server program. Currently, I have it hardcoded to 40000, while the TCP port is 32000 That question was helpful, and led me to add the following line after declaring the UDP port: `s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)` While this gets rid of the initial error, I now have winerror 10013: An attempt was made to access a socket in a way forbidden by its access permissions. What causes THIS error? Thanks, and sorry about my delayed response. – Ythaenagor Apr 12 '20 at 16:20

0 Answers0