UDP socket-port binding & broadcasting

W

Woochi

Guest
For a LAN game im working on, i have the following network setup:

- client & host in 1
- both client and host have:
  • UDP server, at port X
  • UDP socket, at port Y
so, X and Y are the same for everyone. Both parties are intended to be able to broadcast & listen to broadcasts, therefore a UDP server of their own is created.

Host AND client need to send udp, receive udp, send broadcast, receive broadcast. This lead me to the following common configuration:
  • send: through UDP socket, to port Y
  • receive: from port Y (UDP socket)
  • broadcast: through UDP socket, to port X
  • receive broadcast: from UDP server (port X)
Does the setup make sense, as in, is it expected to work logically?

The reason im asking, is because something seems to be off, and i want to be sure im understanding the networking (LAN) logic, and applying it correctly. And if not, i want to fix this before continuing the search for the culprit. For instance, is it correct to assume that the purpose of a UDP server is to *listen* to *broadcasts* only?

EDIT 1:
To elaborate in the issue i mentioned: (UDP) communication does not seem to work, with another computer in the same network. Both IP addresses are within the same range (double checked this with ipconfig , as well as ingame (broadcast & receiving own IP)). Yet it still does not work, even with firewalls completely turned off and no antivirus installed (neither targeted / hardcoded IP UDP nor broadcast). Im at a loss of what to do, having struggled with this issue for about a week now. Any help is appreciated a lot.
 
Last edited by a moderator:

andev

Member
Both don't need a server and a socket. The host has a server, and the clients have sockets.
 
W

Woochi

Guest
Thanks a lot for your reply!

Both don't need a server and a socket. The host has a server, and the clients have sockets.
But... I dont understand. What is the purpose of the UDP server then? To broadcast, or to receive broadcasts? I thought its not possible for a client (or host) to send and at the same time listen to stuff, all on the same port...

Sorry, for asking this many questions. Its just frustrating, the fact that theres so little documentation on this. Ive also googled and found virtually nothing about the relation of UDP servers and broadcasting, and port configs when doing so. And in some posts on this, if i remember correctly, people were explaining that just 1 UDP socket was required per party, no more. That too is why i am confused now, when you say that the host needs no socket, and in fact needs a server.
 

andev

Member
The host has a server, and the clients have sockets.
My wording here is poor, because the server is technically a socket as well.

What is the purpose of the UDP server then?
A "server" just means that a socket is used to communicate with multiple other sockets. Ignoring the port forwarding aspect, the reason you'd want to specify a server is because it's a lot easier if one connection has authority, and the rest sync up with it. Otherwise when there's a conflict of information, who's data do you use? Coin toss?

I thought its not possible for a client (or host) to send and at the same time listen to stuff, all on the same port...
You are mistaken! :p They can (and do) exactly that.
 
W

Woochi

Guest
A "server" just means that a socket is used to communicate with multiple other sockets. Ignoring the port forwarding aspect, the reason you'd want to specify a server is because it's a lot easier if one connection has authority, and the rest sync up with it. Otherwise when there's a conflict of information, who's data do you use? Coin toss?
Aah, i see, so to send broadcasts :D thank you, this is not documented anywhere, as far as i know.

yes, i knew about the importance of broadcating, and have been doing some more reading about it today, as well as general udp stuff: it seems that holepunching from a 3rd party server would be the way to go over WAN, because of how port acces is regulated by NAT etc. At least, either that or manual port opening for pure peer-to-peer (which is a pain imo), is what i understood. (Lastly, theres TCP but god forbid...)

The part i still dont understand, however, is why the other pc over LAN, does not receive anything, even through a simple socket, hard-coded (double checked) target ip. Self-messages do come through :( there shouldnt be problems with ports or firewalls/antivirus (all disabled), it should work but it doesnt... The code is the same but it stops working as soon as the target ip is another pc.
 

The-any-Key

Member
What OP Does the pcs have?
You can't run a game and host server on Windows 8 and think that windows 10 can connect to that. Windows 10 block it. Even if you disable firewall and antivirus.

However. You can start a server on Windows 10 and connect a windows 8. Be sure to enable home group. And allow discovery. Set network to static IP if all fails.
 
W

Woochi

Guest
What OP Does the pcs have?
You can't run a game and host server on Windows 8 and think that windows 10 can connect to that. Windows 10 block it. Even if you disable firewall and antivirus.

However. You can start a server on Windows 10 and connect a windows 8. Be sure to enable home group. And allow discovery. Set network to static IP if all fails.
Sorry for my late reply.
Both are Win10. I have tried those, unfortunately to no avail.
 
Top