Currently I'm working on a project is about chat system between client and agent by using socket.js and PHP.
Recently, received confirmation from client is client server will have load balancer to balance to different server.
Like picture below.
I'm found out an issue from this setup.
Agent A is connected to Server B, but Client A is connected to Server A, so Client A can't communicate with Agent A.
How can I solve this problem by using programming way?
PS:
Client is not allow me to edit any server config file or settings.
Client server is linux server.
Thanks for help :)
we have a similar problem. Right now we have a solution, but it is most likely not the best. When we start our 2 socket servers on 2 different servers, then each server also creates a socketconnection to the other socket server. So each socket server is also a client of the other socket server. When Socket Server A receives a communication it sends it to all connected users AND it also broadcasts it to Socket Server B, and that one sends it then to all connected users again.
Another solution is a Publish/Subscribe broker, like you can find in that link here https://hackernoon.com/scaling-websockets-9a31497af051.
Hope that helps somehow.
Related
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
I am thinking about a scenario where I want to send a data packet from my php service (based on certain behaviour) to a client (can be Android or Windows) connected to it.
A device which is connected to the internet is going to have an ip address.
So is it possible to send a packet (using socket or else) to this ip directly (without polling from client end) and can this data be read from the client.
Scenario is like this :
Client A --------------Registers Own IP Address-----------------> Server
Client B --------------Registers Own IP Address-----------------> Server
Events :
Some changes occur in the database (say)
Server detects the affected client (via some algo),say Client A
Sends a packet to Client A
Client A <--------------Send Data Packet----------------- Server
Is this at-all possible ?
If yes, how effective can this be ?
Please note that, Push notifications is not applicable in my situation.
I am looking for a live (realtime) data transmission system between client and server (both ways).
Any suggestion, help will be useful. Thanx
Absolutely possible to have persistent sockets open.
but I would say this would fail in a hosted environment. GoDaddy etc shuts that down. Been there done that.
I would highly recommend choosing a programming language like java (Whatever you are comfortable with). It is only going to be 200 lines of code.
I am trying to develop a socket.io application. It is just a simple application like the one on the Getting Started - Chat application tutorial in the Socket.IO webpage. But the problem is that, I do not want to have the socket.io server serve the client automatically, because I am planning to have a page (in PHP) have a script that can simultaneously be updated by data from a server in real-time using Socket.IO. I just want a certain client that can connect to the server and let them communicate, not a page served by the socket.io server.
Is this possible? Can you please give an idea on how can it be done. Thanks.
That chat tutorial is just a simple deployment where your own web page wants to connect back to the same server that the web page came from. That is not the only way to do it.
The socket.io client code can be served from anywhere. You can even link to a CDN and get it from there instead of from your own server.
And, likewise, the client can connect to any compatible server as long as the server is configured to accept a connection from your page.
If you're looking for how to connect to a different server, you just specify the URL of the desired host in io.connect() like this:
var socket = io.connect('http://www.example.com');
We have a wireless device (WIFI enabled) that calls a PHP script to enter data into MySQL db. Am trying to find a way to see if the server (through PHP script) can "connect" to the client device (has a microcontroller but doesn't have an OS or display) and pass some data.
The client is a electronic board connected to a gate and the server needs to tell the device to open the gate. Seems to be pretty straight forward but am new to this.
If the client is configured to listen on a specific port, you can open a socket connection to it from the server (using fsockopen()).
You'll need to configure the client though, which I have no idea how to do because your client is nothing standard.
I have server A making a request to server B. I've tried both php's file_get_contents and curl; both refuse the connection. I'm trying to connect to a tomcat application on server B.
The connection does work if I make a request to google.com, or to another application on server B that is not in the Tomcat application.
This leads me to believe there's something specific to my tomcat installation that is rejecting the request from server A. Thoughts? Any more info I can provide to help with the problem?
Is there a way to whitelist my server A in tomcat so the connection is accepted? Or as a last resort how would I accept all requests?
Edit: I also wanted to add that the connection to server B works just fine when I'm connecting from my local development machine.
Your test from server A to google.com or other apps on server B probably use port 80. Many firewalls don't allow traffic on strange ports like 8089.
If you can't change the firewall rule to allow access to serverB:8089, I think the right way to do it is to proxy the request through the server B web server. So server A would request "serverB:80/yourproxyurl" and the web server on server B would talk to the tomcat server on localhost, and output the response.
This is what Tomcat Connectors are for, as I understand it.