Php Notification system and websocket - php

i'm trying to develop a PHP notification service for a CRM used by my customers.
Scenario: an user add an appointment for a collegue, and this collegue has to receive a notification inside his CRM profile like, for example, Facebook did.
The structure is pretty simple: a PHP Server in listening with the client browser connected with Websockets.
Server: i'm using Ratchet - PHP WebSockets, i've followed the examples and started the server, server that is able now to accept connection and deliver messages to all clients connected or just to one receiver.
Client: a simple JS script, with Websocket connection and method, that handle all receiving messagges and notify all to the user connected.
My point is: i'm guessing to have the websocket client browser just for incoming messagge, i don't want to allow them to send nothing, the send part must be done by the server that has access to DB in this way:
1) FORM Appointment
2) Submit to the server and save it to DB, in this step a client PHP Websocket connect to the Ratchet server and send the notification to the receiver.
3) The Websocket of receiver receive the notification and alarm the customer.
The questions are:
what can i use to do the step 2 with the PHP websocket client to connect with the Websocket server? is good to use Pusher interface like this example suggest: http://socketo.me/docs/push or can i avoid using this system?
how can i handle the idle time of websocket client ? a timer that send a ping like message to client for avoiding the dead of websocket?
-how handle possible down of client side or server side?
THanks to all of you!

Related

How to establish a persistent connection to a WebSocket server in Laravel to receive and send messages?

I have created a Laravel backend, which is an API. React frontend interacts with it. The frontend also communicates with the websocket server, receiving messages from it and reacting appropriately from it.
I was given the task of sending messages to a remote web socket from my backend.
I created the defined events to dispatch and listeners for those events. As far as I understand, in listeners I have to send messages to the websocket server. I was trying to use the textalk/websocket library, i.e. creating a websocket connection every time I sent a message to the websocket. It's wrong, but at least it worked. But now I need to keep a permanent connection with this web socket in order to receive messages from it and respond to them. And also I need to still keep sending messages on certain backend events.In general, I need to keep open the connection of my backend with a remote web socket server in order to constantly receive messages from it and in turn send messages to it at certain events within the Laravel application.

Best way to connect two socket servers (node.js and ratchet php)

There are two socket servers that have to send messages to each other. The first one is a node.js server with socket.io. The second is ja php websocket (ratchet - http://socketo.me/).
The second server (ratchet) runs in a php application (created with a php framework like laravel or symfony) that contains a basic chat application.
The node.js server is like a global manager that can convey messages to multiple socket servers.
The communication ways are planned as follows:
Scenario a)
-> client / browser sends a message via websocket
-> php app receives message from browser by ratchet socket and stores this message in database
-> php sends / forwards message to node.js via socket
-> php sends response to client / browser via websocket
Scenario b)
-> node.js server sends a message to all connected php clients via socket
-> php receives message from node.js and stores this message in database
-> php sends this message to one or more connected browser clients
-> browser receives messages from php via websocket
What is the best way to enable this communication way? The browser is already able to talk to the ratchet server. But I have no idea how the ratchet server can talk to the node.js server an act as a normal socket client so that they will establish and hold a connection to each other. Is there a command to send a “hello, I am a new client that wants to establish a connection” message to the node.js server or vice versa?
Is this a good concept at all? Or is there a better way to send socket messages over multiple instances? Are there any tips, tutorials or examples? Other questions to this topic are very old or contains a different setup.
I'd probably use this : https://github.com/ratchetphp/Pawl to have PHP sending messages to nodejs.
Then about the concept being good, I think not.
There is no point in having two differents websockets servers imo.
I'd probably use only one websockets server (nodeJS), and have PHP and node "talk" together through a messaging queue like rabbitMQ / REDIS

Keeping socket open in Swift for chat application

I have a working chat server in Php/Ratchet. I am using Starscream as my client in Swift. I successfully created a chat between users however this only works when my application is open because this is when the socket is open. How do I make my app receive messages even if my app isn't on. So basically is there a way to keep sockets open. I read somewhere that it is forbidden by Apple.
There's a high probability that your process is going to be shutdown by the system at some point, so I wouldn't rely on the app being active in the background.
Try coming up with a solution for receiving past messages when the client becomes online.
Read about Apple Push Notification Service to notify your users about messages while the app is not active.
Sounds like you are sending messages from your client to your phone. You need to send messages to a server and the server sends them to your phone.
The server, if unable to successfully send a message to your phone, should store the message and should send the stored messages to the phone when the phone is available.
There are message queuing systems for things like this. See, for example, RabbitMQ. There are loads of others too that may work better with your tech stack. Do some research.
Here the client talks to the server, the server hooks up with RabbitMQ or whatever you choose to use, RabbitMQ keeps a track of queued messages and when the phone comes online, RabbitMQ sends the queued messages to the server and the server sends them to the phone.
PS Google "message queue PHP".
You need to be in sync with server. Do following steps.
Dump every message in Database i.e. conversation from both parties with timestamp.
When app goes in to background and comes to foreground flush your all messages which are on your screen/local array for showing messages on screen, call a Sync service which will fetch whole conversation, because definitely server will be having all messages, feed you screen with this service response.
The iOS system will receive socket calls at kernel level but will not pass those messages to you app, so you will not get messages while app is in background.
When app is killed you can implement APNS from apple.

Sending message only to particular websocket peer

I am working on a chat website and running php socket server ( using standard php sockets, based on script from https://github.com/sanwebe/Chat-Using-WebSocket-and-PHP-Socket/blob/master/server.php )
its all works fine, but I want to do some extra bits and not sure how it can be done (if can at all)
So the questions are:
Can I authenticate users trying to connect to websocket without them actualy creating connection and then sending login/authentication info via socket message?
How can I identify conneted peers (know which user is connecting to which socket) without them sending some info via socket message.
Can I send messages only to a particular peer connected to websocket server (That would be a main question)?
Thanks

J2ME PHP Push Notification

I want to work on a project which has to do with the server sending notification to the client. The client side is a j2me application and the server side script will be implemented using PHP.
I have found out i can use the push registry API in midp 2.0 for push notifications, but i don't know how to implement this such that a socket connection will be created to the server such that notification can be sent to the client via the socket connection. The notification will then trigger the start of the midlet.
How can i use the push API to create a socket connection between client and server and have notifications sent to the client?
Complete answer is here
In short, there are two ways you might want to do it
Launch the application whenever you receive this "Push SMS"
Launch the application just the next time you receive this 'Push SMS"
For situation (1), you will need to specify this in JAD file. If you do this, the application manager will take necessary steps to launch your application the next time SMS is received.
For situation (2), you will need to write code:
PushRegistry.registerConnection("sms://<port number>","Midlet-Class","*");
The above note of mine would address the issue of launching the application upon incoming SMS. After you launch you can connect to your server and post data or retrieve data. This is a practical way of implementing push for J2ME platform.
But you seem to be wanting to launch the application on incoming network connection; this means you are creating a server socket on the phone and server is trying to establish the connection to the phone applications. I did work in such a situation where the phones were deployed on Motorola's iDen network (pre-2005 era). On such networks, it is possible to assign an IP address to the phone which makes the Push upon incoming network connection feasible. But that's past, on none of the GSM/CDMA networks, atleast at consumer's end, this cannot be supported. Hope it answers your question.
You need to do two things, One you need to listen one port number on the J2ME side for the incoming sms. Next you need to attach one GMS Modem to your computer system, Now send sms using this Modem on a particular port to the mobile you are listening. You can use AT Commands to send SMS.
Please visit this Nokia Link.

Categories