Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The situation is this: I'd like to make a hole punching server for a game and I need to listen to UDP traffic. It will run on a Debian Squeeze VPS so I'm pretty flexible as far as possibilities go.

Everything is extremely basic: the sharing of information is done over http and the backend uses PHP and MySQL. So ideally (or rather, in a simpler and consistent manner) the UDP listener would just run a PHP script with a few parameters extracted from the packet and not return anything to the client.

What would be the best way to approach this? Are there any dangers regarding UDP I should be aware of, apart from the obvious possibility of flooding?

share|improve this question

closed as off topic by Shane Madden, Steven Monday, Khaled, Lucas Kauffman, Iain Jul 23 '12 at 17:04

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 3 down vote accepted

You're looking for PHP's socket interface. See here.

For a game server, I'd wholeheartedly recommend TCP over UDP - packet loss generally isn't acceptable in that context (but I'm not sure quite what you're going for with this one-way communication, either).

share|improve this answer
Actually, it won't be a game server, basically just an info/matchmaking server since it just gathers data from the server player and serves it to interested client players over http. As for php's socket, I thought about using that, but considering I need to keep the server up constantly, wouldn't that cause any issues? Or would running it in CLI mode solve pretty much all problems? – Sašo Apr 26 '12 at 15:30
Right - you wouldn't want to have the socket listener running in your HTTP/CGI processes. You'd want to instead build the listener out as essentially a service/daemon written in PHP, running at all times; set up a service starting script in /etc/init.d and whatnot. Though I'm still not sure this is an appropriate case to set up this kind of listener - couldn't you present an HTTP API for the data that this UDP listener would handle? – Shane Madden Apr 26 '12 at 15:37
Like I said, since it's a VPS it's flexible - if the script (in bash or whatever else) would be simple enough I'd just learn that. I could use an HTTP API (it's already used for the http information requests by the game clients), with a script, but I doubt it would by much more efficient that just running PHP in cli. I'll experiment a bit and see how it goes. – Sašo Apr 26 '12 at 18:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.