Unity 3, webplayer security model and SFS2X policy server
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Unity 3, webplayer security model and SFS2X policy server
Unity 3 introduces a new security model which is similar to Flash and Silverlight.
This is described in more detail here if you want to know more about it:
http://unity3d.com/support/documentatio ... ndbox.html
Practically you can choose between 2 solutions to server policy files:
- SFS2X build in policy serving
- Use the standalone policy server referenced in the Unity manual (or any other standalone policy server)
To use the SFS2X policy server you have to add this command to your game before ANY network call.
Security.PrefetchSocketPolicy(serverIP, serverPort);
Note: the examples distributed with SFS2X are made for Unity 2.6!! And they do not include the policy prefetch command!!!
/Thomas
This is described in more detail here if you want to know more about it:
http://unity3d.com/support/documentatio ... ndbox.html
Practically you can choose between 2 solutions to server policy files:
- SFS2X build in policy serving
- Use the standalone policy server referenced in the Unity manual (or any other standalone policy server)
To use the SFS2X policy server you have to add this command to your game before ANY network call.
Security.PrefetchSocketPolicy(serverIP, serverPort);
Note: the examples distributed with SFS2X are made for Unity 2.6!! And they do not include the policy prefetch command!!!
/Thomas
Policy Prefetch
I dont understand where I should place this line in the lobby code:
Hope you can help me out
Code: Select all
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Entities;
using Sfs2X.Requests;
using Sfs2X.Logging;
public class LobbyGUI : MonoBehaviour
{
public string serverName = "xxxxxxxxxx";
public int serverPort = 9933;
private SmartFox smartFox;
private string zone = "SimpleChat";
private string username = "";
private string password = "";
private string loginErrorMessage = "";
private bool isLoggedIn;
private bool isJoining = false;
private string newMessage = "";
private ArrayList messages = new ArrayList();
// Locker to use for messages collection to ensure its cross-thread safety
private System.Object messagesLocker = new System.Object();
private Vector2 chatScrollPosition, userScrollPosition;
private int roomSelection = 0;
private string [] roomStrings;
public GUISkin gSkin;
private Room currentActiveRoom;
void Start()
{
bool debug = true;
if (SmartFoxConnection.IsInitialized)
{
smartFox = SmartFoxConnection.Connection;
}
else
{
smartFox = new SmartFox(debug);
}
// Register callback delegate
smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection);
smartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
smartFox.AddEventListener(SFSEvent.LOGIN, OnLogin);
smartFox.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
smartFox.AddEventListener(SFSEvent.LOGOUT, OnLogout);
smartFox.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom);
smartFox.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
smartFox.AddLogListener(LogLevel.DEBUG, OnDebugMessage);
smartFox.Connect(serverName, serverPort);
}
Hope you can help me out
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
> To use the SFS2X policy server you have to add this command to your game before ANY network call.
So I would add it right before you do
smartFox = new SmartFox(debug);
or maybe even better first line in Start
/Thomas
So I would add it right before you do
smartFox = new SmartFox(debug);
or maybe even better first line in Start
/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund
So I have it right here:
But once I run it I still get the debug telling me:
Code: Select all
void Start()
{
Security.PrefetchSocketPolicy(serverName, serverPort);
bool debug = true;
if (SmartFoxConnection.IsInitialized)
{
smartFox = SmartFoxConnection.Connection;
}
else
{
smartFox = new SmartFox(debug);
}
But once I run it I still get the debug telling me:
Code: Select all
[SFS DEBUG] TCPSocketLayer: General exception on connection: Thread was being aborted at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.IPAddress address, Int32 port) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.TCPSocketLayer.ConnectThread () [0x00000] in <filename unknown>:0
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
More info required to help.
* Does it work in editor?
* Do you get security exceptions in the player.log/editor.log? (If not, then this is not a problem with policy file)
* More log file needed
/T
* Does it work in editor?
* Do you get security exceptions in the player.log/editor.log? (If not, then this is not a problem with policy file)
* More log file needed
/T
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund
File
Hereby included a Unity 3.3 project which is basically the SFS2X Lobby example with the extra security line and the ip of my SFS2X server already entered. Whenever trying to run this, this will cause a bug report to show in the editor console. http://rapidshare.com/files/453162161/SFSLobby.zip
- Scarpelius
- Posts: 24
- Joined: 12 Mar 2011, 11:33
- Scarpelius
- Posts: 24
- Joined: 12 Mar 2011, 11:33
Code: Select all
[SFS DEBUG] TCPSocketLayer: General exception on connection: Thread was being aborted at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.IPAddress address, Int32 port) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.TCPSocketLayer.ConnectThread () [0x00000] in <filename unknown>:0
Thats what I get, it connects but it gives this error in the background.
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
I'll re-iterate
-----
More info required to help.
* Does it work in editor?
* Do you get security exceptions in the player.log/editor.log? (If not, then this is not a problem with policy file)
* More log file needed
-----
More info required to help.
* Does it work in editor?
* Do you get security exceptions in the player.log/editor.log? (If not, then this is not a problem with policy file)
* More log file needed
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund
You should read this:
http://unity3d.com/support/documentatio ... ndbox.html
And use something like this:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" to-ports="1200-10000"/>
</cross-domain-policy>"
http://unity3d.com/support/documentatio ... ndbox.html
And use something like this:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" to-ports="1200-10000"/>
</cross-domain-policy>"
We finaly have solved this problem after some hours of testing:
Here is the result:
if(Security.PrefetchSocketPolicy(serverName,serverPort,200))
{
... do server connect
}
As you can see you have to check for a valid policy result and add a timeout value of 200 ms and thats it
works in unity editor and inside browser
Here is the result:
if(Security.PrefetchSocketPolicy(serverName,serverPort,200))
{
... do server connect
}
As you can see you have to check for a valid policy result and add a timeout value of 200 ms and thats it
works in unity editor and inside browser
Hello,
I also have an issue with this. I added this line Security.PrefetchSocketPolicy in the Start function and all works in the computer where I have smartfox installed. However when I try to connect with my laptop which is inside the network with an ip like 192.168.xxx.xxx nothing seems to happen.
What actually happens is that Security.PrefetchSocketPolicy returns false in my laptop but true in my server computer... I do not run any firewalls in either machine and there are no blocked ports in the network..
Any ideas?
I also have an issue with this. I added this line Security.PrefetchSocketPolicy in the Start function and all works in the computer where I have smartfox installed. However when I try to connect with my laptop which is inside the network with an ip like 192.168.xxx.xxx nothing seems to happen.
What actually happens is that Security.PrefetchSocketPolicy returns false in my laptop but true in my server computer... I do not run any firewalls in either machine and there are no blocked ports in the network..
Any ideas?
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Hmmm - I dont have any ideas to why the prefetch would return false instead of true for local address in your end. Definitely if thats the case and it didnt return a policy - then the webplayer will fail.
Poke the Unity guys on the Unity forums - best advice I can give for now
/Thomas
Poke the Unity guys on the Unity forums - best advice I can give for now
/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund
Who is online
Users browsing this forum: No registered users and 84 guests