UDP question

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

stevets
Posts: 60
Joined: 11 Jul 2010, 12:22
Location: USA

UDP question

Postby stevets » 29 Aug 2010, 00:43

Hi,

I have run the examples for SFS2X with no trouble. I am now trying to modify the UNITY3D Connector example to use the UDP channel.

I added a new UDP port, in addition, to the TCP port. The ports are both set to 9933. The smartfox.log reports back that both UDP and TCP were successfully created.

I reviewed your "GettingStarted with the UDP protocol" and tried to make a simple modification to the Unity3D Connector example.

I added an event listener,

smartfox.AddEventListener(SFSEvent.UDP_INIT, onUdpInit)

To the onConnection function, I added,

smartfox.InitUDP();

I created a new function called onUDPInit that is supposed to print "UDP Ready" when the UDP_Init event occurs.
However, I do not think that the UDP_INIT event is firing.
Also, Unity does not seem to complain when I add the smartfox.InitUDP(), so it appears to find the Smartfox2.dll.

I looked at the actionscript 3 API and found some info that does not appear in the Unity Api docs. I am not sure if I should assume they are the same.
Does Unity use UDP_INIT or something else?
What are the parameters that InitUDP(?,?,?) accepts, if any?
Should I be using the connection event for TCP to send the InitUDP()?

Thanks,

Steve
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 29 Aug 2010, 07:37

Hey Steve,

The AS3 InitUDP takes various parameters to the InitUDP, but the Unity dll doesnt. This is due to UDP only being supported by the AS3 API in some cases (only in standalone flash - not web). In Unity dll we support it all the time and thus we dont need to specify which UDPmanager to use.

Back to your question. The event listener should definitely fire on response from the server (it does in my unit tests).

Any error messages? What does the console log say when you run loggin in e.g. info level?

/Thomas
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Aug 2010, 07:55

My apologies for this, there's evidently an error with the docs.
The initialization of the UDP channel should be done after having logged in. This is because the server security system doesn't allow a generic connection (not User) to start a UDP session.

I am in the process of updating the docs. They will be up in a moment.
Sorry for the inconvenice :oops:
Lapo
--
gotoAndPlay()
...addicted to flash games
stevets
Posts: 60
Joined: 11 Jul 2010, 12:22
Location: USA

Postby stevets » 29 Aug 2010, 08:01

Hi Thomas and Lapo,

Thanks for the help.

I'll wait for the docs update.

Steve
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Aug 2010, 08:15

Done.
Lapo

--

gotoAndPlay()

...addicted to flash games
stevets
Posts: 60
Joined: 11 Jul 2010, 12:22
Location: USA

Postby stevets » 29 Aug 2010, 08:38

Thanks for the fast fix!

Just one more question. Do I add the sfs-config.xml to the Unity Project tab and , if so, does it go next to the API?

Thanks,
Steve
stevets
Posts: 60
Joined: 11 Jul 2010, 12:22
Location: USA

Postby stevets » 29 Aug 2010, 09:21

Sorry :?
Found the answer in the SmartFox Class members for the Unity API.

Steve
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 29 Aug 2010, 11:56

Super that we caught another issue there.

Does it otherwise work for you now, Steve?

/Thomas
stevets
Posts: 60
Joined: 11 Jul 2010, 12:22
Location: USA

Postby stevets » 29 Aug 2010, 12:19

Hi Thomas,

Yes, it is now working :D

But.....I had to figure out one last thing.
The sfs-config.xml file example should use <SmartFoxConfig> instead of
<SmartFoxClient> in the C# LoadConfig method XML example (Unity API)

Maybe, it should also be clarified in the "Getting started with the UDP protocol" under "Client Side Configuration"?
I might not have the full story yet, let me know:)

Thanks for the help,

Steve
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 29 Aug 2010, 13:26

Damn - documentation error. Thanks for finding :-)

Yes - you need <SmartFoxConfig /> in the config file and not as LoadConfig documentation writes <SmartFoxClient />

Will fix that - thanks

/Thomas
stevets
Posts: 60
Joined: 11 Jul 2010, 12:22
Location: USA

Postby stevets » 30 Aug 2010, 12:05

Hi,

I have been looking through the documentation and cannot figure out how to choose when the (Unity API) extension request is sent by UDP vs. TCP.

The Actionscript 3 API seems to allow for a boolean: useUDP, as well as, the server side com.smartfoxserver.v2.api.SFSAPI.

How would I send the following example, from your Unity API documentation, as UDP? Am I on the wrong track here?

The following example shows how to send a custom extension request
CopyC#
ISFSObject parameters = SFSObject.NewInstance();
smartFox.Send( new ExtensionRequest("MyExt", parameters) );

Thanks,
Steve
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 31 Aug 2010, 05:19

Hey Steve,

Basically you simply add a boolean true as the 4th parameter to the ExtensionRequest constructor:

Code: Select all

public ExtensionRequest(string extCmd, ISFSObject parameters, Room room, bool useUDP)


And thats it!

If you dont want to specify the room parameter, then put in null. Thats the default.

So in your example:

Code: Select all

smartFox.Send( new ExtensionRequest("MyExt", parameters, null, true) );



/Thomas
stevets
Posts: 60
Joined: 11 Jul 2010, 12:22
Location: USA

Postby stevets » 31 Aug 2010, 07:24

Thanks Thomas :D
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 31 Aug 2010, 09:50

Any time.

If you run into any issues then poke me - its the last added feature, so its thus also the least tested.

/Thomas
berry
Posts: 11
Joined: 06 Sep 2010, 09:53

Postby berry » 30 Sep 2010, 07:23

Hi,

I placed a config.xml file in the root of my Unity project folder to configure the application for using UDP. This seems to work in the editor, I'm still a bit concerned about this when it comes to uploading my application (and config.xml) to a server. I can't see how this is going to work. Basicly because when a user opens the page that embeds the application, his browser will fetch the .unity3d file and will run it on the users computer (that's why they need a unity player to see your application in the firstplace, right?). Then there's no way of the application being able to find the config.xml there. Could anyone confirm this?

Is there a way to compile the config file into the final application? Even though that would kind of beat the purpose of having the serperate config file in the first place, it would enable me to run my unity application with UDP.

Berry

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 63 guests