Need to Understand How Setup and Run a Server Socket php web file

Hi,

Ok, I just began using PHP, and my main goal is to understand sockets, since my site will rely mostly upon sockets…

My background in sockets is in Java…so I know that the server program has to constantly be running for it to receive and sent information between a client or many clients.

Now, this is where things become weird for me since I have just started php or web programming…

from the client point of view, someone accessing the site, how does the server socket begin at my end and how does the client socket remain connected at the clients or the user’s end?

That’s the big problem I have, I can’t seem to be able to make or visualize the connection between the two instances at the web address that accesses the site.

Can anyone help me understand this.

I have to add that I am running a localhost…I am able to load the site from any within the network computer and any outside network computer so that’s fine…

but I need to know whether I have to start running the server socket at my end first, and then from another computer load or access the client site?

Just making sure, but you do understand that socket programming is not the same as web programming. You actually need two separate programs, the client and the server.

The server would be running and listening to a port.
The client would try to access that port and be directed by the server.

If I were doing anything with sockets currently, I would be looking towards Python, Java, or C#, not PHP for this.

I understand that much that both the server and client run separately.

But what I don’t understand at which point is the server socket going to run and remain running, is at server side or at client side?

And to answer the other part of your suggestion, I don’t use JAVA because you need to have an SSL certificate to run the applets, and that’s not cheap…I don’t use python because just like php, I don’t know how to use python…and I don’t use C# because I want this to be a pure HTML and PHP site.

The server will stay running. Think of it in terms of a website. Just because your computer is not going to the page daily, does not mean it is not running.

so how do I get the server to start running?

do I have to start it from the server side or the client side?

Based on these questions, I am guessing that you have not looked into this very closely. Learn PHP first, before trying to write your own programs. It will only make you more confused and distract you from actually learning properly.

Ok but you are not answering the question.

This is why I posted in the beginner forum…what’s wrong with my question?

Socket programming tends to be an advanced level topic. You need to understand a fair bit about a variety of technologies to effectively create something using them.

It’s kind of like saying, I just learned my ABC’s, now I am going to write a novel. It just doesn’t work like that.

You know you could’ve said that to begin with…since I need to learn everything and as much as possible…saying I don’t PHP sends me back to where I started, the PHP beginner forum…thanks…now if I were to ask the question that I asked in this forum, how would I rephrase it to GOOGLE the information…or to post it in the Advanced PHP forum?

You know you shouldn’t be so harsh if you are going to penalize me for asking “what is a number” in a mathematics class, if the class says, first grade?

How about this. Tell us about what you are trying to do overall, not how to do it the way you think you should do it. Perhaps sockets is not really the thing to be looking into.

If you think I am being harsh, you need to grow thicker skin. I was not “penalizing” you for your question. If you feel you understood programming enough to ask the question, you should also understand enough what to search for, until then, leave it as something to work towards.

I answered the question clearing up any assumptions that I had.

So, it boils down to, learn to program first following tutorials, reading books, and understand what and how code works. Then, progress to more advanced topics.

I already read the sockets manual at php.net, it is all straight forward but I don’t understand where and how the server would load, so it can run, for it to receive commands from the client.

and to answer your previous post.

The site (the where the video game would run from) has to have sockets because it will need the clients request information from the server so that the server can manage what the client sees.

I don’t know anyone who has used php in this way, and I haven’t myself.

This walks through some of the basics of connecting.
http://www.codeproject.com/Tips/418814/Socket-Programming-in-PHP

man this sockets subject is so tight nit that not even youtube you can a dissent video that can explain how both the server and client run…I will keep looking.

I did understand the basics of sockets thanks…I know sockets in Java.

but I still don’t understand whether the server will run at the webserver side and accept connection from the client?

As a moderator on this site, I see where both you and the readers of your posts are confused.

First, you are not asking questions about an item that has a set answer because you have not
shown us any code or samples of where you code is failing. Next, those who have attempted to
help have asked and hinted that more information needs to be sent if you wish their help.

Now, it appears that you may understand Java Sockets and may want to use a PHP version of them.
Here is a simple tutorial that may help you in understanding PHP sockets. Hopefully it will help you.
Once you run into trouble, please post back here with code segments that fail you and we can help.

http://www.binarytides.com/php-socket-programming-tutorial/

By the way, there are many PHP socket samplers and tutorial on Google if you want to view others.
Hope this helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service