Connect to online server from Unity editor

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Post Reply
Elzean
Posts: 13
Joined: 11 Jul 2014, 07:24

Connect to online server from Unity editor

Post by Elzean »

I am trying to make a Client program with Unity, i can test with the standalone smartfox server but now i need to test with an existing smartfox server online. There is already a client made with Flash and i got the source of this client, so i copied the server name and port from it.

If i test in Unity standalone i get this error :

Code: Select all

[SFS DEBUG] TCPSocketLayer: Connection error: No connection could be made because the target machine actively refused it.
If i test with Unity for web i get this :

Code: Select all

Security Exception. Policy file load failed!

Code: Select all

[SFS DEBUG] TCPSocketLayer: General exception on connection: Unable to connect, as no valid crossdomain policy was found
The code i'm using is from the Tris Unity example :

Code: Select all

void Awake() {
		Application.runInBackground = true;

		//StartCoroutine("Login");

		// In a webplayer (or editor in webplayer mode) we need to setup security policy negotiation with the server first
		if (Application.isWebPlayer || Application.isEditor) {
			if (!Security.PrefetchSocketPolicy(serverName, serverPort, 500)) {
				Debug.LogError("Security Exception. Policy file load failed!");
			}
		}		

		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.AddLogListener(LogLevel.DEBUG, OnDebugMessage);

		smartFox.Connect(serverName, serverPort);
	}
The server has a crossdomain, which is working with flash :

Code: Select all

<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
I am doing something wrong ? Do i need to adjust some settings on the server in order to connect from Unity editor directly (without having to upload on the server where is smartfox) ?

Thanks for your help !
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Connect to online server from Unity editor

Post by Lapo »

Does the Flash client connect from the same computer without problems?
Lapo
--
gotoAndPlay()
...addicted to flash games
Elzean
Posts: 13
Joined: 11 Jul 2014, 07:24

Re: Connect to online server from Unity editor

Post by Elzean »

Well i'm not sure how to proceed with their sources, i get lots of error trying to build it. They send me the sources but they are not the ones who made it. I'm just trying to get what i can from it in order to start the Unity Client.

Within their smartfox admin online there is this in the top :

Code: Select all

Server instance: server.example.com:9933
Is this the right server i should use for "serverName" and "serverPort" in my code ?
Elzean
Posts: 13
Joined: 11 Jul 2014, 07:24

Re: Connect to online server from Unity editor

Post by Elzean »

Also i see their version is 2.6.0 can this cause issues ?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Connect to online server from Unity editor

Post by Lapo »

Elzean wrote: Within their smartfox admin online there is this in the top :

Code: Select all

Server instance: server.example.com:9933
Is this the right server i should use for "serverName" and "serverPort" in my code ?
No, that seems a fake domain name, that doesn't resolve to a real server.
You will need the real IP address or domain name of the server.
Also i see their version is 2.6.0 can this cause issues ?
No, no problems with that.
Lapo
--
gotoAndPlay()
...addicted to flash games
Elzean
Posts: 13
Joined: 11 Jul 2014, 07:24

Re: Connect to online server from Unity editor

Post by Elzean »

Yeah sorry i didnt write the real domain, but it's in that fashion just with a real domain, it's within their smartfox admin which is working with their current version of the game. So i wonder if this info is the right one ?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Connect to online server from Unity editor

Post by Lapo »

I have no idea, to be honest :) Presumably so.
You should connect with the AdminTool and see if the server is running.
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply