I'm trying to create PHP server to communicate with multiple WPF applications (c#), I want it similar to signalR working, where client will subscribe and server broadcast the updates to all clients subscribe with the server. Please suggest how to start this, I have WPF application running, I need to create the PHP server, i think socket will be used here, as client application will be running all the time and listening to any update from the server. Any Hint is appreciable.
1 Answer
As you guessed you need to implement sockets to enable communication between your server and the clients. Find a explanation and code example in this youtube video (C#). For the beginning this should help you with your server (php) implementation.
Typically the server is listening for incoming connections and will then deal with them (like it is explained in the video). As I do not know enough of your environment I suggest two options:
One: You make your clients listen for incoming connections. In reference to the video you need to switch the implementations of the server and client socket. For establishing a connection between the server and the client the server needs an address which is normally the ip address.
Two: You can use the typical approach and let the server listen for connections. To imitate the function of the server pushing to the client, you could use a timer at client site and recurringly ask the server for an update. This approch is handy in the case that you can not address your clients from the server as you may not know their ip address for example.
You may want to improve your performance with threading. Find further information here