hello, I am using Netgroups with FMS(rtmfp). I can connect to the Netgroup (reiceve NetStatusEvent "NetGroup.Connect.Success") but that is all. I can't post anything or see that someone has joined the Netgroup, no NetStatusEvent fires. What am I missing?
_groupSpecifier = new GroupSpecifier(test_group);
_groupSpecifier.postingEnabled = true;
_groupSpecifier.multicastEnabled = true;
_groupSpecifier.serverChannelEnabled = true;
_netGroup = new NetGroup(_nc, _groupSpecifier.groupspecWithAuthorizations());
_netGroup.addEventListener(NetStatusEvent.NET_STATUS, groupNetStatusHandler);
Here is the code. After user connects to the group, I want to send everyone in the group a message.
public function connect(url:String):void {
_nc = new NetConnection();
_nc.client = this;
_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_nc.connect(url);
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code){
case "NetConnection.Connect.Success":
createGroup();
break;
case "NetGroup.Connect.Success":
//!!!post msg to the group, no one receives this message
var message:Object = new Object;
message.text = "Hello";
message.sender = _nc.nearID;
_netGroup.post(message);
break;
default:
trace("event.info.code: " + event.info.code);
break;
}
}
private function createGroup():void {
_groupSpecifier = new GroupSpecifier("test_group");
_groupSpecifier.postingEnabled = true;
_groupSpecifier.multicastEnabled = true;
_groupSpecifier.serverChannelEnabled = true;
_netGroup = new NetGroup(_nc, _groupSpecifier.groupspecWithAuthorizations());
_netGroup.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
}
After reading documentation I am a little bit confused, if I am using FMS do I have to write some server side code to bootstrap users? And can I use netgroup.post() or I need to call my custom server side function that will go through all application clients and inform them about some action?
Before calling the post() method, you should check for the NetGroup.Neighbor.Connect event. Once this event is received then you can call the post() method. So, try creating one more client and connect to the same GroupSpecifier. And after the above mentioned event is received, call the post() method.
That is the problem, I can not receive any NetGroup event, except NetGroup.Connect.Success. In flash media server console I see that users connect to the server, but I don't receive any NetGroup event on the client side. Do I have to add neighbors manually an the client side? Or do I have to implement some server side code?
You don't have to implement any server side code. Just keep a blank app on the server and make two client side apps.
In the first client side app, add the following case.
case "NetGroup.Neighbor.Connect":
//!!! post msg to the group, no one receives this message
var message:Object = new Object;
message.text = "Hello";
message.sender = _nc.nearID;
_netGroup.post(message);
break;
Don't put above code under - case "NetGroup.Connect.Success"
In the 2nd client side app, keep everything same as the 1st client. Just comment out the above mentioned code under case "NetGroup.Neighbor.Connect".
After this, 1st run the 1st client and then the 2nd client, you'll receive both the events:"NetGroup.Neighbor.Connect" and "NetGroup.Posting.Notify".
Thanks for the help, but as I told I do NOT receive any other Netgroup event exept NetGroup.Connect.Success. There is no events as NetGroup.Neighbor.Connect or NetGroup.Posting.Notify. I made simple class wihtout even post message:
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.NetStatusEvent;
import flash.net.GroupSpecifier;
import flash.net.NetConnection;
import flash.net.NetGroup;
public class Main extends Sprite {
private var _netGroup:NetGroup;
private var _nc:NetConnection;
private var _groupSpecifier:GroupSpecifier;
public function Main():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
_nc = new NetConnection();
_nc.client = this;
_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_nc.connect('rtmfp://192.67.1.48/test_room/');
}
private function netStatusHandler(event:NetStatusEvent):void {
trace("-->> event.info.code: " + event.info.code);
if (event.info.code == "NetConnection.Connect.Success") {
createGroup();
}
}
private function createGroup():void {
_groupSpecifier = new GroupSpecifier("test_group");
_groupSpecifier.multicastEnabled = true;
_groupSpecifier.postingEnabled = true;
_groupSpecifier.serverChannelEnabled = true;
_netGroup = new NetGroup(_nc, _groupSpecifier.groupspecWithAuthorizations());
_netGroup.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
}
}
}
Even if I connect many users to the same room after I join the group, I get into the output only theese events. Basically user doesn't know that someone has joined that room.
-->> event.info.code: NetConnection.Connect.Success
-->> event.info.code: NetGroup.Connect.Success
//1st client as file (TestPost.as)
package {
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.net.GroupSpecifier;
import flash.net.NetGroup;
public class TestPost extends Sprite {
var _nc:NetConnection;
var _groupSpecifier:GroupSpecifier;
var _netGroup:NetGroup;
public function TestPost() {
// constructor code
connect("rtmfp://serverIP/app_name");
}
public function connect(url:String):void {
_nc = new NetConnection();
_nc.client = this;
_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_nc.connect(url);
}
private function netStatusHandler(event:NetStatusEvent):void {
trace("NetStatusEvent : "+event.info.code);
switch (event.info.code){
case "NetConnection.Connect.Success":
createGroup();
break;
case "NetGroup.Connect.Success":
break;
case "NetGroup.Neighbor.Connect":
//!!! post msg to the group, no one receives this message
var message:Object = new Object;
message.text = "Hello";
message.sender = _nc.nearID;
_netGroup.post(message);
break;
default:
trace("event.info.code: " + event.info.code);
break;
}
}
private function createGroup():void {
_groupSpecifier = new GroupSpecifier("test_group");
_groupSpecifier.postingEnabled = true;
_groupSpecifier.multicastEnabled = true;
_groupSpecifier.serverChannelEnabled = true;
_netGroup = new NetGroup(_nc, _groupSpecifier.groupspecWithAuthorizations());
_netGroup.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
}
}
}
//2nd client as file(TestPost_1.as)
package {
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.net.GroupSpecifier;
import flash.net.NetGroup;
public class TestPost_1 extends Sprite {
var _nc:NetConnection;
var _groupSpecifier:GroupSpecifier;
var _netGroup:NetGroup;
public function TestPost_1() {
// constructor code
connect("rtmfp://serverIP/app_name");
}
public function connect(url:String):void {
_nc = new NetConnection();
_nc.client = this;
_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_nc.connect(url);
}
private function netStatusHandler(event:NetStatusEvent):void {
trace("NetStatusEvent : "+event.info.code);
switch (event.info.code){
case "NetConnection.Connect.Success":
createGroup();
break;
case "NetGroup.Connect.Success":
//!!! post msg to the group, no one receives this message
/*var message:Object = new Object;
message.text = "Hello";
message.sender = _nc.nearID;
_netGroup.post(message);
break;*/
default:
trace("event.info.code: " + event.info.code);
break;
}
}
private function createGroup():void {
_groupSpecifier = new GroupSpecifier("test_group");
_groupSpecifier.postingEnabled = true;
_groupSpecifier.multicastEnabled = true;
_groupSpecifier.serverChannelEnabled = true;
_netGroup = new NetGroup(_nc, _groupSpecifier.groupspecWithAuthorizations());
_netGroup.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
}
}
}
First run the 1st client and then run the 2nd client. I have tried at my end and it's working.
North America
Europe, Middle East and Africa
Asia Pacific