Comments (9)
@rodriguesfas can you please try this ?
from codeigniter-websocket.
Thanks for answering me.
This link you sent me, I have already tested the application and it works very well.
However, it sends the message from ws in the frontend. I'm needing to send the message inside the php controller.
I'm trying to use Broadcast messages with your php App that you suggested in the documentation, but it doesn't work for me, I was wondering if you have a working example of this part or if you would put more details on how it works.
from codeigniter-websocket.
I'm trying to run that example of yours, but to no avail.
from codeigniter-websocket.
I'm trying to run that example of yours, but to no avail.
I'm experiencing same issue. Did you manage to solve?
I even changed the 0.0.0.0 to localhost (like: "ws://localhost:8282") but still no success.
from codeigniter-websocket.
Please look at the Welcome.php controller.
public function index()
{
// Load package path
$this->load->add_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket');
$this->load->library('Codeigniter_websocket');
$this->load->remove_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket');
// Run server
$this->codeigniter_websocket->set_callback('auth', array($this, '_auth'));
$this->codeigniter_websocket->set_callback('event', array($this, '_event'));
$this->codeigniter_websocket->set_callback('roomleave', array($this, '_roomleave'));
$this->codeigniter_websocket->run();
}
public function _roomleave($data = null)
{
// Here you will receive data from the frontend roomleave event trigger.
echo 'Hey ! I\'m a room leave EVENT callback' . PHP_EOL;
}
The main concept is the callback function.
You would receive the response into the defined function. You can trigger the event from the front end like below using jQuery
socket.send(JSON.stringify({
'type': 'roomleave',
'room_name': targetName,
'user_id': "buzz4rd"
}));
It would trigger the function below
public function _roomleave($data = null)
{
// Here you will receive data from fron tend roomleave event trigger.
echo 'Hey ! I\'m a room leave EVENT callback' . PHP_EOL;
}
Please look at this Room Chat using PHP websocket. It was built using this
from codeigniter-websocket.
from codeigniter-websocket.
Please look at the Welcome.php controller.
public function index() { // Load package path $this->load->add_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket'); $this->load->library('Codeigniter_websocket'); $this->load->remove_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket'); // Run server $this->codeigniter_websocket->set_callback('auth', array($this, '_auth')); $this->codeigniter_websocket->set_callback('event', array($this, '_event')); $this->codeigniter_websocket->set_callback('roomleave', array($this, '_roomleave')); $this->codeigniter_websocket->run(); } public function _roomleave($data = null) { // Here you will receive data from the frontend roomleave event trigger. echo 'Hey ! I\'m a room leave EVENT callback' . PHP_EOL; }
The main concept is the callback function.
You would receive the response into the defined function. You can trigger the event from the front end like below using jQuery
socket.send(JSON.stringify({ 'type': 'roomleave', 'room_name': targetName, 'user_id': "buzz4rd" }));
It would trigger the function below
public function _roomleave($data = null) { // Here you will receive data from fron tend roomleave event trigger. echo 'Hey ! I\'m a room leave EVENT callback' . PHP_EOL; }
Please look at this Room Chat using PHP websocket. It was built using this
Hi, thanks for the explanation. Maybe I didn't explain well what I'm trying to do, I have two PHP applications, I want to send data from one to the other, but I don't want it through the front end, but backend to backend.
Thank you in advance for your attention in answering me.
from codeigniter-websocket.
Hi there, Thanks your suggestions did work indeed. I have another question though. Using php, how can I check which clients are currently active? My problem: What is a specific user has multiple open tabs of the same page, then each tab has the same client id. This causes glitches, so technically each page needs it’s own client id. However, I need to broadcast to all of these tabs for that user… This means I need to know which client id’s are active. Kind Regards, Jaco Jaco SJ Krüger B.Eng Mechanical Engineering Performance Manager Mobile: +27 79 361 0853 Website: www.basecloudglobal.com<http://www.basecloudglobal.com/> [A close up of a logo Description automatically generated]https://www.basecloudglobal.com/ [review-us-google]https://www.google.com/search?authuser=1&source=hp&ei=Ev9bXcDtNtDVwQLyxa64Dw&q=basecloud&oq=basecloud&gs_l=psy-ab.3..0i10l4j0i10i30j0i30j0i10i30l2j0i5i30l2.1561.2806..3059...1.0..0.435.2824.3-7j1......0....1..gws-wiz.....2..35i39j0i131j0j0i67.u-O_luTJYQQ&ved=0ahUKEwjAvviG0JHkAhXQalAKHfKiC_cQ4dUDCAU&uact=5#lrd=0x1e955fa6b3d0fdb5:0x5dcd69d9d6690d4a,1,,, From: Taki Elias @.> Sent: Tuesday, 21 December 2021 15:01 To: takielias/codeigniter-websocket @.> Cc: Jaco SJ Krüger @.>; Mention @.> Subject: Re: [takielias/codeigniter-websocket] broadcast-messages-with-your-php-app-boom- (#22) @rodriguesfashttps://github.com/rodriguesfas @JacoSJKrugerhttps://github.com/JacoSJKruger Please look at the Welcome.php controller. public function index() { // Load package path $this->load->add_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket'); $this->load->library('Codeigniter_websocket'); $this->load->remove_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket'); // Run server $this->codeigniter_websocket->set_callback('auth', array($this, '_auth')); $this->codeigniter_websocket->set_callback('event', array($this, '_event')); $this->codeigniter_websocket->set_callback('roomleave', array($this, '_roomleave')); $this->codeigniter_websocket->run(); } public function _roomleave($data = null) { // Here you will receive data from the frontend roomleave event trigger. echo 'Hey ! I'm a room leave EVENT callback' . PHP_EOL; } The main concept is the callback function. You would receive the response into the defined function. You can trigger the event from the front end like below using jQuery socket.send(JSON.stringify({ 'type': 'roomleave', 'room_name': targetName, 'user_id': "buzz4rd" })); It would trigger the function below public function _roomleave($data = null) { // Here you will receive data from fron tend roomleave event trigger. echo 'Hey ! I'm a room leave EVENT callback' . PHP_EOL; } Please look at this Room Chat using PHP websockethttps://github.com/takielias/ci-socket-chat. It was built using thishttps://github.com/romainrg/ratchet_client — Reply to this email directly, view it on GitHub<#22 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AWMUY3JV3KUXE7A2G77GE7LUSB3ALANCNFSM5DI2VH6Q. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you were mentioned.Message ID: @.@.>>
Define a global array of logged-in users. If you get a new logged-in user in that array it means already logged in. Disconnect the previous one and active the new one. Simple solution.
from codeigniter-websocket.
@rodriguesfas @JacoSJKruger
Please look at the Welcome.php controller.public function index() { // Load package path $this->load->add_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket'); $this->load->library('Codeigniter_websocket'); $this->load->remove_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket'); // Run server $this->codeigniter_websocket->set_callback('auth', array($this, '_auth')); $this->codeigniter_websocket->set_callback('event', array($this, '_event')); $this->codeigniter_websocket->set_callback('roomleave', array($this, '_roomleave')); $this->codeigniter_websocket->run(); } public function _roomleave($data = null) { // Here you will receive data from the frontend roomleave event trigger. echo 'Hey ! I\'m a room leave EVENT callback' . PHP_EOL; }
The main concept is the callback function.
You would receive the response into the defined function. You can trigger the event from the front end like below using jQuerysocket.send(JSON.stringify({ 'type': 'roomleave', 'room_name': targetName, 'user_id': "buzz4rd" }));
It would trigger the function below
public function _roomleave($data = null) { // Here you will receive data from fron tend roomleave event trigger. echo 'Hey ! I\'m a room leave EVENT callback' . PHP_EOL; }
Please look at this Room Chat using PHP websocket. It was built using this
Hi, thanks for the explanation. Maybe I didn't explain well what I'm trying to do, I have two PHP applications, I want to send data from one to the other, but I don't want it through the front end, but backend to backend.
Thank you in advance for your attention in answering me.
Why don't you use rest API?
from codeigniter-websocket.
Related Issues (20)
- Server will not run after running manual command HOT 1
- Stuck in connection phase when app is deployed to AWS. HOT 2
- Keeping the server running permanently? HOT 1
- websocket doesnt respond new user HOT 1
- user_id receiving same message when user_id and recipient_id is the same HOT 4
- Error using the client class for sending message to users HOT 3
- How to change the socket hostname and port address without running commands on command prompt ? HOT 15
- Error call controller, can you help me? HOT 1
- I'm not sure why I can only 255 connections be established by Websocket Server HOT 1
- How to use with HTTPS? HOT 1
- How to get all connected users list? HOT 1
- How to get closed thread information? HOT 1
- Not sending message via php HOT 2
- Question about user_id and recipient_id HOT 1
- Socket always running? HOT 2
- https http wss ws HOT 2
- Cannot connect to web socket HOT 1
- running server manually on macos (apple silicon) HOT 1
- Is there any way to restart the WebSocket server? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codeigniter-websocket.