• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

NetConnection - Multiple "clients"

Guest
Aug 13, 2009 Aug 13, 2009

Copy link to clipboard

Copied

Hi all,

  Let's say I have two different Flash apps (remote from each other) and joined by the same NetConnection.  Now, they both set the NetConnection "client" property (e.g. nc.client = <whatever>".  On one of the apps (the one I incidentally start first), it receives all remote "client" calls from the script sitting on my Flash Media Server.  However, the second app (which sets the .client property in the same way) never receives ANY of those client calls.

  Is it possible to have more than one custom "client" set for a NetConnection?  Or am I missing something here?

  Thanks in advance!

Cheers,

Duncan

Views

3.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Aug 13, 2009 Aug 13, 2009

Copy link to clipboard

Copied

I dont think its possible to have two clients on same netconnection. In real sense, a client is nothing but a netconnection and its one to one mapping. I think you are not stating your problem correctly. Can u pass me the code and what is your objective , then probably i might be able to help you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

I promise you I'm stating my problem correctly.

Each Flash app has a NetConnection to the same FMS (same FMS application, same port, etc.).  But, if you're telling me there can only be one "client" set per FMS application, then please confirm that.

Here's the code used on both ends (essentially):

(from the init() method in the client:)

...

  nc = new NetConnection();
  rtmpGo="rtmp://whatever/wherever";

  var ph:ProxyChatRequest = new ProxyChatRequest();
  ph.addEventListener("finalizeEvent", handleFinalize);
  nc.client = ph;

  nc.connect();
..

where "nc" is a NetConnection object.  ProxyChatRequest is simply an extra class that handles the NetConnection callbacks.  It works on one Flash app but not the other.

Thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

No I don't mean there can be only one client to FMS application. What i meant is you can one client per netconnection , not single client to FMS app. Now if both clients are two different swf's each having its own NetConnection , that callbacks should happen for both clients. Is it possible for you to share both your server-side and client-side code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

Yes, two different SWFs that each have its own NetConnection is what's happening here.

Server-side code is attached here (I'm assuming you're ok with the client-side code I pasted before; if not, let me know what else you need from the client sides):

//Two-element array
vidStreams=["right","left"];

var client;

//Application first starts
application.onAppStart = function()
{
application.SOBarOnline = SharedObject.get("SOBarOnline", false);
};

//A currentClient (user) attempts to connect
application.onConnect = function(currentClient)
{
//Reject connection if array is empty
//(Two users are currently using application)
if (vidStreams.length <= 0)
{
  application.rejectConnection(currentClient);
}

//Store array element in currentClient property
currentClient.cliNow=vidStreams.pop();
application.acceptConnection(currentClient);

if (currentClient.cliNow == "left") {
  client = currentClient;
}

currentClient.streamSelect = function()
{
  //Sent the property to Client object
  return currentClient.cliNow;
};

currentClient.freeStream = function ()
{
  vidStreams.push(currentClient.cliNow); 
};

application.SOBarOnline.setProperty("msg", "User joined.");
};

Client.prototype.requestChat = function (reqID, destID)
{
  client.call("barRequestWaiting", null, reqID, destID);
  application.SOBarOnline.setProperty("msg", reqID + " requested chat.");
}

Client.prototype.finalize = function (reqID)
{
trace(reqID);
client.call("finalize1", null, reqID);
}

application.onDisconnect = function(currentClient)
{
//When currentClient leaves put the element back in array
vidStreams.push(currentClient.cliNow);
application.SOBarOnline.setProperty("msg", "User left.");
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

I suppose it will call only one of those client's callback namely one which is has it property "cliNow" as "left as its current client and you are assigning client variable that way - so when it does "call" it goes back to that "left" client.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

Ahhh I see!  Is there a way around this?  Or do I have to track each client connection and then iterate through them to send the "call"?  I'm not quite sure how this would work (I'm fairly new to this).  Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

Ya that is one way you can do : basically put all clients in an array , iterate through them and make calls, in your case its just two , so i suppose you can do that. But now if you want something to be called on client side and its same function you want to be called on some condition, you can use application.broadcast, this will basically call an handler on all clients.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

Ok, well, what if I moved the "requestChat" method into the onConnect method on the FMS?  E.g. I'd add the following code

application.onConnect = function(currentClient)

{

...

currentClient.requestChat = function (reqID, destID)
{
  trace("Requesting chat...");
  currentClient.call("barRequestWaiting", null, reqID, destID);
  application.SOBarOnline.setProperty("msg", reqID + " requested chat.");        // THIS FAILS
};

...

};

I just tried this but it's giving me an error when it's called (on the line marked "THIS FAILS").  It says:

"Sending error message: Response object not found (_result:0)."

Does this mean I MUST have a callback/responder object set and I can't just use "null" as the second parameter?

Thanks again for your help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

I think what you are saying is gettign error on previous line and not one which you have marked by comment:

This line : currentClient.call("barRequestWaiting", null, reqID, destID); - getting you in error ??

It's not needed to define responder everytime , can you just try this.call instead of currentClient.call ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

I'm positive the line I marked is throwing the error since I get the "trace" statement just fine.

The "currentClient" line is definitely throwing an error   I also tried your suggestion of "this.call" but it throws the same error.

Surely there must be a way to get this to work?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

You don't need to define a responder... I think it's a scope issue:

currentClient.call("barRequestWaiting", null, reqID, destID);

should be

this.call("barRequestWaiting", null, reqID, destID);

... as the function is within the scope of currentClient.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

Hi Jay,

  I have tried that and I still get the same error...I was sure to reload the application before trying to test it, as well.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

Sorry... I didn't spot the previous reply suggesting the scope issue.

When you get the warning in the log, are the call to barRequestWaiting and the ShareObject update failing?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2009 Aug 14, 2009

Copy link to clipboard

Copied

No worries.

As far as I can tell, the call to barRequestWaiting is failing, and the subsequent SharedObject update isn't being called at all (I don't actually see the SO update anywhere on any of the clients).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 17, 2009 Aug 17, 2009

Copy link to clipboard

Copied

LATEST

Does anyone else have any ideas?  Thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines