takielias / codeigniter-websocket Goto Github PK
View Code? Open in Web Editor NEWCodeigniter WebSocket Built for real-time application.
Home Page: https://ebuz.xyz
License: MIT License
Codeigniter WebSocket Built for real-time application.
Home Page: https://ebuz.xyz
License: MIT License
I followed the tutorial, and it worked very well, but after I completed step 2, I closed the server via ctrl+c and tried the manual command "php index.php welcome index". I receive this error as a response:
An uncaught Exception was encountered
Type: WebSocket\ConnectionException
Message: Could not open socket to "0.0.0.0:8282": Connection refused (111).
Filename: /opt/lampp/htdocs/codeigniter/vendor/textalk/websocket/lib/Client.php
Line Number: 95
Backtrace:
File: /opt/lampp/htdocs/codeigniter/vendor/textalk/websocket/lib/Base.php
Line: 48
Function: connect
File: /opt/lampp/htdocs/codeigniter/application/models/Classic_firearms.php
Line: 25
Function: send
File: /opt/lampp/htdocs/codeigniter/index.php
Line: 315
Function: require_once
If I try to run "php vendor/takielias/codeigniter-websocket/install.php --app_path=application" again, the server starts and immediately closes and returns back to the command line. Did I do something wrong?
Is there a way to run the socket without doing it manually and have it always work?
How can i let the reviser and the sender see messages
when we upload to real server , should we change connection code? it's working now but sometimes it crash . and somtimes i get this error
WebSocket connection to 'ws://localhost:8282/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
should we change this part of code on real host?
var conn = new WebSocket('ws://localhost:8282');
Hi there,
I've changed the php text to "ws://localhost:8282" as having it as 0.0.0.0 was giving a 10049 error (where as localhost doesn't give any error).
Still it seems to not be working correctly. If I connect via javascript it seems to be working fine, but when I send a message using php I don't get anything.
PHP (not working)
`public function test_webs(){
$socket_client = new WebSocket\Client("ws://0.0.0.0:8282");
$socket_client->send(json_encode(array('user_id' => 1, 'message' => null)));
$socket_client->send(json_encode(array('user_id' => 1, 'message' => 'Super cool message to myself!')));
}`
javascript (working fine)
`var conn = new WebSocket('ws://localhost:8282');
var client = {
user_id: 5,
recipient_id: null,
type: 'socket',
token: null,
message: null
};
conn.onopen = function (e) {
conn.send(JSON.stringify(client));
console.log("Socket open");
};
conn.onmessage = function (e) {
var data = JSON.parse(e.data);
if (data.message) {
console.log("Incomming User "+data.user_id+": ");
console.log(data.message);
}
if (data.type === 'token') {
// $('#token').html('JWT Token : ' + data.token);
console.log('JWT Token : ' + data.token);
}
};`
Assistance will be appreciated.
Hi!
Great work on this library.
I would like to know if it is possible to use UUID (String) instead of an ID (Interger).
I thank you for your attention.
am having this error
Unable to load the requested class: Codeigniter_websocket
so i was checking the path and i didn't find the (romainrg) folder in vendor
i re install the library twice and didn't work
any suggestions ?
I have a use your sample in my project for one to one notification, every thing is working after running "php index.php welcome index" command, after i upload these files to server it will not executing correctly, i can't able run this command on server so i want to know where all i should change this host name and port number manually
How to get closed thread information?
Hi everybody!
I searched the method to stop the websocket server but i did not found.
I need this to disable some services on my server when it is in high load. But I need that my Apache keep working. (restart Apache is out of case).
This library is awesome. Congratulations for it
How to get all connected user list which is live/active users ?
Hi!
Could you give me more details on how to use this piece of code: https://github.com/takielias/codeigniter-websocket#broadcast-messages-with-your-php-app-boom-
Please, if it's not too much bother, put an example of use. Hug.
I uploaded my project on web
it works on computer but on mobile phone the websocket isn't pushing messages
any solutions ?
i used your example with my live server and i found that with https its fails to connect.
i tried to find some solution over google but not work.
i found 1 solution for this to add .crt and .pem file in ratchet function parameter but i don't no how to add that files in this library
i have this both file but don't no how to pass this 2 files in parameter
i am using shared hosting
Hello ,
It is working fine in http server....But how can implement same in HTTPS server ?
I connected vuejs and c++ fronted using websocket server.
But server connected only 255.
I have run the web socket as shown in the command below:
$ php index.php test index
Running server on host 0.0.0.0:8282
Authentication activated
However, when I tried on the client side, I am getting the console message as:
WS connection attempt ${4-ctx.tryCount} -> Unsuccessful
Please kindly assist. Thanks in advance.
PS: I edit the view to show if it is connected or not. Below is the code.
var wsFactory = { tryCount: 3,
connect : function(url){
var ctx = this,
ws = new WebSocket(url);
return new Promise(function(v,x){
ws.onerror = e => { console.log('WS connection attempt ${4-ctx.tryCount} -> Unsuccessful');
e.target.readyState === 3 && --ctx.tryCount;
if (ctx.tryCount > 0) setTimeout(() => v(ctx.connect(url)), 1000);
else x(new Error("3 unsuccessfull connection attempts"));
};
ws.onopen = e => {
console.log('WS connection Status: ${e.target.readyState}');
console.log("here: "+client.user_id);
conn.send(JSON.stringify(client));
$('#messages').append('<font color="green">Successfully connected as user ' + client.user_id + '</font><br>');
v(ws);
};
ws.onmessage = m => {
console.log(m.data);
var data = JSON.parse(e.data);
if (data.message) {
$('#messages').append(data.user_id + ' : ' + data.message + '<br>');
}
if (data.type === 'token') {
$('#token').html('JWT Token : ' + data.token);
}
};
});
}
};
wsFactory.connect("ws://blablabla.com:8282")
.then(ws => ws.send("Hey..! This is my first socket message"))
.catch(console.log);
I really appreciation your great work. Your work has really helped a lot.
Thus, an issue occurred if a particular user is the initiator of the chat, the user would be able to send message out but would also be the receiver of that same message provided that the user_id and recipient_id are both the same. However, if both user_id and recipient_id differs, the code works fine.
The problem now is to be able to differentiate user_id from recipient_id even if they both have same id value.
Thank you!
Is it possible to make it work with multiple recipients? Like a group chat.
I tried to use this code to send messages to the client:
$client = new Client('ws://0.0.0.0:8282');
$client->send(json_encode(array('user_id' => 1, 'message' => null)));
$client->send(json_encode(array('user_id' => 1, 'message' => 'Super cool message to myself!')));
And I have used this line to import the library:
use WebSocket\Client;
This is giving me this error:
Socket Error 10049 - The specified address is not available from the local computer
¿How can I solve this?
http://localhost/websocket/user/index/1
it shows me this!! i think the problem is from code igniter it self !
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.39 (Win64) OpenSSL/1.1.1b PHP/7.3.4
My source code has config Route and remove index.php and using sql server.
When run 'php index.php welcome index ', it show error:
`C:\xampp\htdocs>php index.php welcome index
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function sqlsrv_connect()
Filename: C:\xampp\htdocs\system\database\drivers\sqlsrv\sqlsrv_driver.php
Line Number: 144
Backtrace:
File: C:\xampp\htdocs\application\controllers\Load_Page.php
Line: 8
Function: __construct
File: C:\xampp\htdocs\index.php
Line: 315
Function: require_once`
So I got this library to work in localhost, but I can't seem to get it to work on my AWS Lightsail instance. I did everything in the readme, but no dice.
I changed the WebSocket in welcome_message.php to have the IP of my server
var conn = new WebSocket('ws://555.555.555.5:8282');//fake ip for security
And I wrapped conn.send in in a try and catch block to to see if I could catch anything:
$('#submit').click(function () {
client.message = $('#text').val();
client.token = $('#token').text().split(': ')[1];
client.type = 'chat';
if ($('#recipient_id').val()) {
client.recipient_id = $('#recipient_id').val();
}
try {
conn.send(JSON.stringify(client));
} catch (error) {
console.log(error);
}
});
The Try/catch block throws this error:
DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
It seems to always be stuck in the connection phase. Do I need to open up a port or something?
I get this error when i call the client class to send message to users connected on the socket
$client = new Client('ws://127.0.0.1:8080');
$client->send(json_encode(array('user_id' => 1, 'message' => null)));
$client->send(json_encode(array('user_id' => 1, 'message' => 'Super cool message to myself!')));
Here is the error:
An error has occurred: Connection to 'ws://127.0.0.1/' failed: Server sent invalid upgrade response:
I install the project example and it works fine
but when i install the library to an existing project by using this command
php vendor/takielias/codeigniter-websocket/install.php --app_path=application
i get this Error. i update composer and same error i got
Severity: Error
Message: Interface 'Ratchet\MessageComponentInterface' not found
Filename: C:\xampp\htdocs\shareweight\vendor\takielias\codeigniter-websocket
libraries\Codeigniter_websocket.php
Line Number: 186
Are there any special deamons to keep the server running forever? I found this, but if there is something specific for this library, I want to use that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.