Giter Site home page Giter Site logo

Comments (9)

takielias avatar takielias commented on August 26, 2024

@rodriguesfas can you please try this ?

from codeigniter-websocket.

rodriguesfas avatar rodriguesfas commented on August 26, 2024

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.

rodriguesfas avatar rodriguesfas commented on August 26, 2024

Captura de tela de 2021-10-07 09-20-27

I'm trying to run that example of yours, but to no avail.

from codeigniter-websocket.

JacoSJKruger avatar JacoSJKruger commented on August 26, 2024

Captura de tela de 2021-10-07 09-20-27

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.

takielias avatar takielias commented on August 26, 2024

@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 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.

JacoSJKruger avatar JacoSJKruger commented on August 26, 2024

from codeigniter-websocket.

rodriguesfas avatar rodriguesfas commented on August 26, 2024

@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 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

@JacoSJKruger

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.

takielias avatar takielias commented on August 26, 2024

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.

takielias avatar takielias commented on August 26, 2024

@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 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

@JacoSJKruger

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.