參考文章
NetConnection成功後的設定
var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/groupOne"); groupspec.postingEnabled = true; groupspec.ipMulticastMemberUpdatesEnabled = true; groupspec.addIPMulticastAddress("225.225.0.1:30303"); group = new NetGroup(nc,groupspec.groupspecWithAuthorizations()); group.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
Event 的處理
要加上
case "NetGroup.Connect.Success": connected = true; break;
case "NetGroup.Posting.Notify": receiveMessage(event.info.message) break;
接受的處理
private function sendMessage(txt:String):void
{
var message:Object = new Object(); message.text = txt;
message.sender = group.convertPeerIDToGroupAddress(nc.nearID);
message.userName = txtUser.text; group.post(message);
receiveMessage(message);
}
private function receiveMessage(message:object):void {
trace(message.userName+": "+message.text);
}