2

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?

1 Answer 1

3

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).

3
  • 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, 2012 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? Apr 26, 2012 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, 2012 at 18:16

Not the answer you're looking for? Browse other questions tagged .