application.onAppStart = function() {
	trace("onAppStart");
};

//新客户端连接时触发
application.onConnect = function(client, uName) {
	trace("onConnect = "+uName);
	client.UserName = uName;
	application.acceptConnection(client);//允许客户登录,如果要对客户身份做验证,在此扩展即可 	
	hellomsg="system message"+client.UserName+" 進入房間";
	application.broadcastMsg("showmsg",hellomsg);//调用所有client的showmsg方法,并传递参数hellomsg(客户端的代码中,必须有对应的showmsg函数)
	
	//定义服务端的sendmsg方法,以便客户端能调用
	client.sendmsg = function(msg) {
		mesg = client.UserName+": "+msg;
		//每次client调用本方法后,服务器同步广播到所有client
		application.broadcastMsg("showmsg",mesg)
	};
	
};

//有客户端断开连接时触发
application.onDisconnect = function(client) {
	trace("onDisconnect ="+client.UserName);	
	hellomsg="system message"+client.UserName+" 離開房間";
	application.broadcastMsg("showmsg",hellomsg)
};
application.onAppStop = function() {
	trace("onAppStop");
};