Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How do I make the server to send data to clients?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Plusekwal   Members   -  Reputation: 102

Like
0Likes
Like

Posted 20 June 2011 - 12:36 PM

Problem:
My game contains a room where everyone who has started the game can chat - this is the menu for joining and creating rooms in multiplayer. This is why I can't make that chat peer to peer - so I made all clients to send chat data to a server and then check if there are any new messages. The problem is that the never-ending requests for chat data to the server seem like a DoS attack and the host of the server blocks my access temporarily.

What I need:
I have decided to make the chat push and not pull based - the clients will only send their chat messages and listen for incoming data, and the server will send all messages to all connected clients on regular interval. In this way it won't block players who imitate a DoS attack. But I'm fairly new in php and here come the questions.

1. Someone told me that proc_* and sock_* are unsafe and therefore are forbidden on a shared hosting(which I use). Then how do I make the server to send data to clients? Which functions should I use?
2. How can the server understand if the internet connection of a player has accidentally stopped and he couldn't tell the server he stopped playing?
3. Is it better to stop using php for chat and use IRC instead? I'm using a shared hosting and I have probably no more than 3% or 4% of a server's bandwidth.

Sponsor:

#2 rip-off   Moderators   -  Reputation: 8518

Like
1Likes
Like

Posted 20 June 2011 - 12:55 PM

How frequently were you polling for messages? If you poll every few seconds you shouldn't look like a DOS attack.

Offloading the chat to IRC could be a good solution.

#3 hplus0603   Moderators   -  Reputation: 5533

Like
1Likes
Like

Posted 20 June 2011 - 01:37 PM

But I'm fairly new in php and here come the questions.


3. Is it better to stop using php for chat and use IRC instead? I'm using a shared hosting and I have probably no more than 3% or 4% of a server's bandwidth.


PHP Is *not* a good language for "long poll" type situations. (Google for "long poll" and "comet" to see this mechanism described in more detail)
Each waiting child process doesn't see any of the other children, so you'd have to go through something like a shared database, which would be terrible for efficiency.
If your choice is "PHP or nothing" then you either have to put in an IRC plug-in on your web site, or live with the terrible performance you'll get out of PHP.
enum Bool { True, False, FileNotFound };

#4 Plusekwal   Members   -  Reputation: 102

Like
0Likes
Like

Posted 22 June 2011 - 05:53 AM

How frequently were you polling for messages?

As soon as the game recieved some data from the server, it requested another one. I dont know if the chat getting updated every 5-6 seconds would be nice for the players.

PHP Is *not* a good language for "long poll" type situations. (Google for "long poll" and "comet" to see this mechanism described in more detail)

That's why I'm looking to implement a push-type chat.

If your choice is "PHP or nothing" then you either have to put in an IRC plug-in on your web site, or live with the terrible performance you'll get out of PHP.

Are you saying I can't make a good irc client built in the game with PHP? I'm fine with whatever technology satisfies my needs.

#5 hplus0603   Moderators   -  Reputation: 5533

Like
0Likes
Like

Posted 22 June 2011 - 08:36 PM

If your choice is "PHP or nothing" then you either have to put in an IRC plug-in on your web site, or live with the terrible performance you'll get out of PHP.

Are you saying I can't make a good irc client built in the game with PHP? I'm fine with whatever technology satisfies my needs.


I am saying that if you use PHP the way everybody uses PHP, as a per-request scripting language within Apache or nginx, then no, you cannot make a useful IRC client with PHP.

For a persistent server, you need a persistent process. HTTP, Apache, and PHP are not persistent processes in this regard, because there is one "process" per request, and it dies as soon as the request is gone. Typical servers that allow long-running processes are servers that are not web based -- anything from something custom in C++, Java or C#, to something you write on top of node.js.

For a persistent, reactive response on the client, you either need a continuous connection -- with a game client, this is simple. With a web browser, you have to use WebSockets, Flash with sockets, or a custom plug-in of some sort, or you will have to double-buffer a form of long polling using XMLHttpRequest.
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS