PDA

Volledige versie bekijken : SendAndLoad in ASC crashed de Appilicatie


Alexw
%Europe/Berlin %499 %2008, 12:58
Hey,

Ik gebruik Flash Media Server 3.
En ik heb de volgende service-side script:

Server-Side:

application.allowDebug = true;

application.onAppStart = function(){
this.clientUniqueID = 0;

this.chat = SharedObject.get("chat", false);
this.chat.sendMessage = function(msg, user, room, receiver){
if(receiver == "ALL"){
var newMessage = user + ": " + msg;
} else {
var newMessage = user + "(PRV): " + msg;
}

this.send("receiveMessage", newMessage, room, receiver);
}
this.chat.SetOnline = function(id, user, room){
this.Username[id] = user;
this.Chatroom[id] = room;

var LV:LoadVars=new LoadVars();
LV.sendAndLoad("http://localhost/functions.php?fun=SetOnline&var1="+this.Username[id]"&var2="+room);
this.send("UpdateList", room);

trace("User: "+this.Username[client._uniqueID]+" has connected to '"+this.Chatroom[client._uniqueID]+"'");
}
}

application.onConnect = function(client){
application.acceptConnection(client);

client._uniqueID = this.clientUniqueID;

client.call("setUserID", null, this.clientUniqueID);

this.clientUniqueID++;
}

application.onDisconnect = function(client){
trace("User: "+this.Username[client._uniqueID]+" has disconnected from '"+this.Chatroom[client._uniqueID]+"'");

var LV:LoadVars=new LoadVars();
LV.sendAndLoad("http://localhost/functions.php?fun=SetOffline&var1="+this.Username[client._uniqueID]);
this.send("UpdateList", this.Chatroom[client._uniqueID]);
}


En de Applicatie wordt na het laden gelijk gecrashed.
De Applicatie werkt alleen als ik alle LV.sendAndLoad wegghaal.
Weet iemand hoe ik het anders kan aanpakken, om een user online/offline te maken in mysql op server-side.

Alvast bedankt,
Alexw

shebanian
%Europe/Berlin %518 %2008, 13:26
Het zou kunnen zijn dat hij bij het LV.sendAndLoad crashed, omdat de php pagina niet helemaal klopt rood is de hoe het nu gaat en groen is wat je wilt...

LV.sendAndLoad("http://localhost/functions.php?fun=SetOnline&var1="+this.Username[id]"&var2="+room);

moet dat niet met een extra + voor &var2 zijn...

LV.sendAndLoad("http://localhost/functions.php?fun=SetOnline&var1="+this.Username[id]+"&var2="+room);

Alexw
%Europe/Berlin %522 %2008, 13:31
I fixed that.
But it keep crashing.

Alexw

shebanian
%Europe/Berlin %536 %2008, 13:52
De volgende code geeft geen alert....

alert ("Javascript runs...");
var LV:LoadVars = new LoadVars();
LV.sendAndLoad("http://localhost/functions.php?fun=SetOnline&var1="+this.Username[id]+"&var2="+room+"");

deze code wel....

alert ("Javascript runs...");
var LV =new LoadVars();
LV.sendAndLoad("http://localhost/functions.php?fun=SetOnline&var1="+this.Username[id]+"&var2="+room+"");

Hoop dat het een beetje helpt...

Jan
%Europe/Berlin %556 %2008, 14:21
LV.sendAndLoad("http://localhost/functions.php?fun=SetOnline&var1="+this.Username[id]"&var2="+room);

public sendAndLoad(url:String, target:Object, [method:String]) : Boolean

Je hebt geen target opgegeven.

Groeten,
http://users.telenet.be/jansurf/cwo.png Jan

Alexw
%Europe/Berlin %668 %2008, 17:02
Nope, Dat was het ook niet.
Ik krijg wel 2 errors in Flex:

Severity and Description Path Resource Location Creation Time Id
missing ; before statement, var LV:LoadVars=new LoadVars(); ServerSideCoding main.asc line 20 1220626669281 5
missing ; before statement, var LV:LoadVars=new LoadVars(); ServerSideCoding main.asc line 40 1220626669312 6

Ik snap niet hoe ik het kan oplossen.

Alexw

Jan
%Europe/Berlin %708 %2008, 18:00
FMS is AS1 (niet AS2!)
En dus kan/mag je ook geen strikt datatyping toepassen.
var LV:LoadVars=new LoadVars(); //geeft errors (:LoadVars en vooral die ":" begrijpt ie niet op die plaats)
var LV=new LoadVars();// is ok

application.onDisconnect = function(client){
trace("User: "+this.Username[client._uniqueID]+" has disconnected from '"+this.Chatroom[client._uniqueID]+"'");

var LV:LoadVars=new LoadVars();
LV.sendAndLoad("http://localhost/functions.php?fun=SetOffline&var1="+this.Username[client._uniqueID]);
this.send("UpdateList", this.Chatroom[client._uniqueID]);
}
this.send("UpdateList", this.Chatroom[client._uniqueID]); gaat ook niet werken want met this refereer je naar de application instance en niet naar je sharedObject instance

Dit topic hoort trouwens thuis in de Flash Server development rubriek en niet in de serverside scripting rubriek.


Groeten,
http://users.telenet.be/jansurf/cwo.png Jan

Alexw
%Europe/Berlin %737 %2008, 18:41
Als ik de appilicatie start krijg ik deze error in de Log bij FMS:
Sending error message: C:\Program Files\Adobe\Flash Media Server 3\applications\Chatrooms\main.asc: line 39: TypeError: this.Username has no properties

Alexw

Jan
%Europe/Berlin %048 %2008, 02:10
Je maakt Username aan binnen de scope van het SharedObject maar je vraagt het in regel39 op in de scope van van de Application instance. Eigenlijk zelfde opmerking als laatste regel van hierboven. (this.send()); Ook heb je nergens die array geïnstantieerd.

Daarenboven is het geen goed idee om heel je server logic / structuur op te hangen aan het sharedObject. Het dient daar niet voor en je zou hiervoor normaal gezien de Application instance of eventueel gedeeltelijk de Client instance gebruiken.
En als je 'dingen' als UserName in het SharedObject wil opslaan omdat je hier ook via de client side aan wil kunnen dan moet je rso.setProperty(key,value) gebruiken wat het server side equivalent is van rso.data.key=value;

Groeten,
Jan

Alexw
%Europe/Berlin %483 %2008, 12:35
Dus als ik het goed begrijp:

Client Side:
//Bij het verbinden
nc.connect("rtmpt://SERVERIP/Chatrooms",User);

Server Side:
application onConnect = function(client,username){
application.acceptConnection(client);

client._uniqueID = this.clientUniqueID;

client.call("setUserID", null, this.clientUniqueID);

client.setProperty("user_" + this.clientUniqueID,username);
var LV:LoadVars=new LoadVars();
LV.send("http://localhost/functions.php?fun=SetOnline&var1=user_"+client._uniqueID);

this.clientUniqueID++;
}

application onDisconnect = function (client){
var LV:LoadVars=new LoadVars();
LV.send("http://localhost/functions.php?fun=SetOffline&var1=user_"+client._uniqueID);
}


Moet dit werken?
Alexw

Jan
%Europe/Berlin %495 %2008, 12:53
Nee...
FMS is AS1 (niet AS2!)
En dus kan/mag je ook geen strikt datatyping toepassen.
var LV:LoadVars=new LoadVars(); //geeft errors (:LoadVars en vooral die ":" begrijpt ie niet op die plaats)
var LV=new LoadVars();// is ok
Groeten,
http://users.telenet.be/jansurf/cwo.png Jan
Waarom gebruik je rtmpt(unneling) ipv rtmp?

Alexw
%Europe/Berlin %499 %2008, 12:58
Oeps typefoutje.
En als je rtmp gebruikt?
nc.connect("rtmp://SERVERIP/Chatroom",User);

En dus ook als ik :LoadVars weghaal?
Werkt het dan wel.

Alexw

Jan
%Europe/Berlin %517 %2008, 13:25
Tja wat hierboven staat zal wel werken maar je zit nog steeds met die UserName wat volgens mij een array is. Maar je hebt die nergens aangemaakt en wil er toch zomaar elementen insteken of uit opvragen. Dat kan niet.
Je kan in Flash niet zomaar vanuit het niets scripten:
reeks[0]="jan";
trace(reeks[0]);//undefined
je moet eerst instantiëren:
var reeks=new Array();
//en dan pas kan je er elementen insteken
En verder:
rtmpt gebruik je als je een probleem hebt met een firewall (omwille van port 1935).
Die t staat voor tunneling en dan wordt het rtmp protocol in feite in een http omhulsel gestoken en pollt de client voortdurend via POST requests.
rtmp gaat sneller dan rtmpt maar komt uiteindelijk op hetzelfde neer.

Groeten,
Jan

Alexw
%Europe/Berlin %529 %2008, 13:41
Het is geen array.

De client stuurt de Username naar de server.
En komt uit eindelijk zo: user_0, user_1, user_2, etc.
En die bevatten dan Usernames.

Alexw

Jan
%Europe/Berlin %549 %2008, 14:11
Het gaat hier over:
this.chat.SetOnline = function(id, user, room){
this.Username[id] = user;
en hier:
application.onDisconnect = function(client){
trace("User: "+this.Username[client._uniqueID]+" has disconnected from '"+this.Chatroom[client._uniqueID]+"'");
en samen met dit:
client._uniqueID = this.clientUniqueID;
en dit:
application.onAppStart = function(){
this.clientUniqueID = 0;
en dit:
this.clientUniqueID++;
Kan ik daar niks anders uit afleiden dan dat Username een array is want je gebruikt integers om een value toe te kennen aan een key.

En als het geen array is maar een object dan mag je geen integers gebruiken want variabelen en instance names mogen niet met een cijfer beginnnen of enkel uit een cijfer bestaan.
Username.1="jan"; //dat mag niet

Vooral die regel in je onDisconnect bewijst dat:
trace("User: "+this.Username[client._uniqueID]+" has disconnected from '"+this.Chatroom[client._uniqueID]+"'");
Daar staat dan toch:
trace("User: "+this.Username[13]+" has disconnected from '"+this.Chatroom[13]+"'");
Dus een (index based) array...


Groeten,
Jan

Alexw
%Europe/Berlin %556 %2008, 14:22
Ik heb er dit van gemaakt:
application.allowDebug = true;

application.onAppStart = function(){
this.clientUniqueID = 0;

this.chat = SharedObject.get("chat", false);
this.chat.sendMessage = function(msg, user, room, receiver){
if(receiver == "ALL"){
var newMessage = user + ": " + msg;
} else {
var newMessage = user + "(PRV): " + msg;
}

this.send("receiveMessage", newMessage, room, receiver);
}
}

application onConnect = function(client,username){
application.acceptConnection(client);
client._uniqueID = this.clientUniqueID;
client._username = username;

client.call("setUserID", null, this.clientUniqueID);

var LV=new LoadVars();
LV.send("http://localhost/functions.php?fun=SetOnline&var1="+client._username);

this.clientUniqueID++;
}

application onDisconnect = function (client){
var LV=new LoadVars();
LV.send("http://localhost/functions.php?fun=SetOffline&var1="+client._username);
}


Maar dan crashed hij weer....

Alexw

Jan
%Europe/Berlin %567 %2008, 14:37
application onConnect
->
application.onConnect
en
application onDisconnect
->
application.onDisconnect
:S

Groeten,
Jan

Alexw
%Europe/Berlin %581 %2008, 14:57
Het werkt nu alles zoals het hoort.

Hartstikke bedankt,
Alexw