1

I have a server that firstly takes a TCP connection, then, on another thread, listens for a specific UDP packet (from all sources on a port) to be noticed and the endpoint associated with and used alongside the TCP connection.

My question is: Is it possible for one thread of my program to listen to a port from any connection and another thread to only listen to a specific endpoint? This seems wrong.

Also, is there an easier way to establish a UDP connection parallel to a TCP connection that can utilize UDP hole punching implementation?

Note: I'm trying to keep this all on one port, instead of using many.

[Edit: Confusing sentence]

Dafeesh
  • 85
  • 1
  • 7
  • http://stackoverflow.com/questions/11488453/can-i-call-accept-for-one-socket-from-several-threads-simultaneously – didierc Jun 18 '14 at 00:35
  • What you probably want is to have a single thread doing all the accepts on the port you setup as listening, and then forward specific clients to a dedicated thread/routine. – didierc Jun 18 '14 at 00:37
  • Also, many platforms discriminate sockets on 3 parameters: IP address, port, and protocol. This means that you should be able to setup several sockets overlapping on some of these parameters, but not all of them. – didierc Jun 18 '14 at 00:43
  • 1
    To the second comment: That is exactly what I am doing. I guess a simpler way of stating my problem is How do I have UdpClient act very much like TcpClient does? I understand its connectionless. I just need it send data parellel to the TcpClient which will handle the actual connection portion. – Dafeesh Jun 18 '14 at 03:03
  • 1
    I will just try to ask the question better here: https://stackoverflow.com/questions/24276532/if-a-tcp-connection-is-made-can-we-assume-udp-can-be-made-on-the-same-endpoint – Dafeesh Jun 18 '14 at 03:21
  • I see. I have little knowledge of firewall internals, but my intuition is that it works like any bijective mapping device we use in software engineering (like `std::map` in C++). If you manage to set your sockets in your program, NATs should act transparently. However, for the initial tcp server socket to be reachable, you'd have to configure the NAT to forward access to it properly. – didierc Jun 18 '14 at 07:54

0 Answers0