yii-node-socket
yii-node-socket copied to clipboard
Command console
Help me please!
You have specified in the documentation that you want to use the console command
./yiic help node-socket
terminal or console shows me an errorbash: ./yiic: No such file or directory
.
On that I use this command./yii help node-socket
is a mistake or not . And how right? Sorry for my English translator google :)
Hi, seems like mistake, is it working?
Hi, thanks for the reply . Socket term. Others are not . To this question I can arrange that on a message in the frontend part and use the information that the message was in the backend . And what kind of data can be transferred ?
Finally Sorry for molestation . I correctly understand that I can use your code socket.on ()
as the soceket.on
as in node.js. And where it is used in the controller or in views. Popravte me if I'm wrong . But I can see the use of after if (Yii :: $ app-> request-> post ()) {
in any action, controllers.
Hi, i am not fully understand your questions, but socket.on used only on client side and by nodejs server,.
Google translator :) you have written in documentation
Now events can be created only on PHP side. All data transmitted in json format. Into callback function data was pasted as javascript native object (or string, integer, depends of your PHP Frame config)
// Add event listener
socket.on ( 'updateBoard', function (data) {
// Do any action
});
The question is which is used in the controller or node.js, and that's where these events are used
socket.onConnect (function () {
// Fire when connection established
});
socket.onDisconnect (function () {
// Fire when connection close or lost
});
socket.onConnecting (function () {
// Fire when the socket is attempting to connect with the server
});
socket.onReconnect (function () {
// Fire when successfully reconnected to the server
});
this events should be used on frontend
Predefined events
socket.onConnect (function () {
// Fire when connection established
});
socket.onDisconnect (function () {
// Fire when connection close or lost
});
socket.onConnecting (function () {
// Fire when the socket is attempting to connect with the server
});
socket.onReconnect (function () {
// Fire when successfully reconnected to the server
});
Custom event which was sent from php or other js client
socket.on('updateBoard', function () {});
This event
// Add event listener
socket.on ( 'updateBoard', function (data) {
// Do any action
});
is used in the js or php
in js
And that
Rooms
socket.onConnect(function () {
socket.room('testRoom').join(function (success, numberOfRoomSubscribers) {
// success - boolean, numberOfRoomSubscribers - number of room members
// if error occurred then success = false, and numberOfRoomSubscribers - contains error message
if (success) {
console.log(numberOfRoomSubscribers + ' clients in room: ' + roomId);
// do something
// bind events
this.on('join', function (newMembersCount) {
// fire on client join
});
this.on('data', function (data) {
// fire when server send frame into this room with 'data' event
});
} else {
// numberOfRoomSubscribers - error message
alert(numberOfRoomSubscribers);
}
});
});