Jump to content

PHP Socket


laponac84

Recommended Posts

Hallo
i start learning Socket and php programming
socketprogramming.jpg

for now successfully manage to make the communication between the client and the server, by sending an automatic message from the system. I am interested in the following: 


  • 1. Does the server can send messages to specific client ? or server send to all client, and then client make filter of message (this is for me, this is not)?
  • 2. How i can menage number of connection ?
  • 3. How i can menage to make live client and server?

I make while(true){ // code } part of code for make server live, but this way is not too functional, because the server does not see what was happening, I can see the response message to the client only

PS: Is there any bether solution ?

 

Link to comment
Share on other sites

1. It can do either. Or both. IRC servers do both: send a chat message to all clients, and send a user-specific message to a specific client.

2. You delve into multi-threading. Briefly, when the server accept()s it creates a new thread to handle the client, and the server immediately waits for the next connection. Meanwhile the new thread does whatever it is supposed to. The main thread and the new thread can communicate with each other too. To manage the number of connections, the server stops accepting connections when it has too many child threads/connections active.

3. I don't know what you mean by "make live".

 

I make while(true){ // code } part of code for make server live, but this way is not too functional, because the server does not see what was happening, I can see the response message to the client only

Don't know what you're trying to say there either.

 

PS: Is there any bether solution ?

What you have there is the standard pattern for a single-threaded server/client architecture. A "better solution" would be multi-threading.
Link to comment
Share on other sites

maybe'm a little confused, but I need the following:

First:
1. the current version of football manager that I made with PHP + MySQL, jQuery ... not contained live online game with two opponents. In this (old version) it was possible to only see the final result (not to be part of live game).
2. i know how to make live game with refreshing page, or div on some "N" second. to read data form Mysql, but this is not ok solution.

Second: what is actually needed?
For example: i have two player online live in the game, i need

  • 1. one server to create events in the game (attack from the left with a strike from the middle of ... , red card ...) and wait (read) to the client signals (two direct players), or more directly, the changes of formation and the players themselves
  • 2. Two (or more) clients for Reading messages from the server (the event that the server will create, change tactics and composition of the teams that will make the other opponent) and send a message to the server (substitutions and tactics)

on Google when you type "PHP client server", most links have a socket, so I read about him

with PHP + MySQL, jQuery i know how to make this, but with lots of refreshing of content, and if i have 10.000 users, i think that this is not smart solution 

What is the best solution for me?

PS1: i make all code in local server (easy php) I also have a good web hosting, if necessary.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.