Problems with UDP sockets

Hello guys,
I am using C# with .Net sockets right now , I am creating a Server - Clients network,
the idea is to send noraml info(like position, rotation etc…) via UDP and to send the most important stuff via TCP.
Now, the TCP works totally fine, but the UDP works only for one side,
I mean, when as I send UDP from some player to the server, it recives it,
but when I send UDP from the server to one of the players, he never recives…
By the way, when the client is on my PC (the server’s PC) it’s do recives it.

Do you have an idea how to fix it?
Is the problem with Open/Closed ports?

the problem is likely nat punchthrough.

TCP is a connection, UDP isn’t, as such you have to establish a two way connection for it to work

Thanks for the fast response , Do I need to use Socket.Conncet or … ? ,
Right now I am using SendTo and Recive from…

You already use socket connect if you work with UDP or TCP. Potentially not visibly but thats where it ends on.

No what you need to do is implement NAT Punchtrough so either the server is portforwarded with open firewall and receives the message and answers on the same port to the client or there is the need to create a middle man server, a connection tester / nat punchthrough service that runs on a machine which fullfills this needs and provides it to server and client

also just to mention: if you intend to use your solution on webplayers don’t forget to implement a policy server on your backend too or use unitys provided one if you write one or the webplayer will not connect anywhere.

I read about NAT Punchtrough, but I am not sure I’ve understood it correctly ,I assume that it has happened because some computers have the same address so we should make a connection with a specific internet address , is that true?

The problem that NAT Punchtrough solves and needs to solve is not ‘about the same address’ but that a computer is not reachable on its public IP. this is a big problem even on global success games from the past like WarCraft 3 with its custom games.

What you got right is how it basically works: both the hosting and the connecting player talk to a 3rd machine, your nat punchthrough service that runs on a machine that is fully udp reachable on the ports and that fakes the ‘ping in’ to open up the firewall.

there is a great article on how nat punchthrough works in skype which should help a lot understanding the problem.

connectivity problems within the same local lan are caused by incorrect code that tries to connect on the public external IP instaed of using lan IPs for connection as you are meant to do (unity networking does that automatically)

I think you didn’t understand me…
I don’t want one player to connect to another, I’m programing a MMORPG, I want the player to send packets of UDP to send position, rotation, etc, and TCP to send any other info.
The TCP works totally fine, the UDP also, but it works just in one direction, the Client sends info, the Server recives,
but when the Server sends info, the Client doesn’t recive.

Is the solution still the same?
and if it does,Do you have any working example to show me?

thanks a lot, and one more thing, u have skype or somthing to talk quicker?

In that case it sounds like you just don’t send it back to the right port (the one you got the data packet from), or that the user simply can’t have any UDP passing at all in which case the only option is TCP fallback