Networking in Web Player build

Is it possible to get networking to work in the web player when not using unitys built in networking code?

I’m getting this in the web player log. Its also looking at a different port to the one i gave it.

desktop: 1920x1080 60Hz; virtual: 3600x1080 at 0,0
Platform assembly: C:\Users\rob\AppData\LocalLow\Unity\WebPlayer\mono\3.x.x\Data\lib\System.dll (this message is harmless)
Platform assembly: C:\Users\rob\AppData\LocalLow\Unity\WebPlayer\player\3.x.x\Data\lib\CrossDomainPolicyParser.dll (this message is harmless)
Trying to login: rob
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
LobbyClient:Login(String, String)
LoginGUI:OnGUI()
 
(Filename: ..\..\Runtime\Export\Generated\BaseClass.cpp Line: 2535)

SocketPolicyClient1: Incoming GetPolicyStreamForIP

SocketPolicyClient1: About to BeginConnect to 192.168.1.105:843

SocketPolicyClient1: About to WaitOne

SocketPolicyClient1: Caught exception: No connection could be made because the target machine actively refused it.



CrossDomainPolicyManager caught an exception while checking endpoint 192.168.1.105: System.ArgumentException: Policy can't be constructed from empty stream.

  at MonoForks.System.Windows.Browser.Net.FlashCrossDomainPolicy.FromStream (System.IO.Stream originalStream) [0x00000] in <filename unknown>:0 

  at MonoForks.System.Windows.Browser.Net.CrossDomainPolicyManager.RetrieveFlashCrossDomainPolicyFrom (System.String host, Int32 port, Int32 timeout) [0x00000] in <filename unknown>:0 

  at MonoForks.System.Windows.Browser.Net.CrossDomainPolicyManager.FlashCrossDomainPolicyFor (System.String connecting_to_ip, Int32 policyport, Int32 timeout) [0x00000] in <filename unknown>:0

mercuryplutus,

Yes, you don’t have to use the built-in networking code. You are likely running into a security issue (as I see in your logs). You’d need to add this line of code before attempting to connect (using the server’s ip and port):

Security.PrefetchSocketPolicy("127.0.0.1", 9899);

The server you’re connecting to would need to respond over that port with a policy file that gives the Unity Web Player permission.

Hopefully that helps.

Also, here is how you would connect and login using ElectroServer via the web player. Notice the ‘prefect’ line.

using UnityEngine;
using System.Collections;
using Electrotank.Electroserver5.Api;
using Electrotank.Electroserver5.Core;

public class Main : MonoBehaviour {

    ElectroServer es = new ElectroServer();

	// Use this for initialization
	void Start () {

        es.Engine.Queueing = EsEngine.QueueDispatchType.External;

        es.Engine.ConnectionResponse += OnConnectionResponse;
        es.Engine.LoginResponse += OnLoginResponse;

        Server server = new Server("server1");
        AvailableConnection availCon = new AvailableConnection("127.0.01", 9899, AvailableConnection.TransportType.BinaryTCP);
        server.AddAvailableConnection(availCon);

        es.Engine.AddServer(server);

        Security.PrefetchSocketPolicy("127.0.0.1", 9899);

        es.Engine.Connect();
	
	}

    void OnLoginResponse(LoginResponse e) {
        if (e.Successful) {
            Debug.Log("logged in!");
        } else {
            Debug.Log("login failure!!");
            Debug.Log(e.Error.ToString());
        }
    }

    void OnConnectionResponse(ConnectionResponse e) {
        Debug.Log("connection success: " + e.Successful.ToString());

        if (e.Successful) {
            LoginRequest lr = new LoginRequest();
            lr.UserName = "guest";

            es.Engine.Send(lr);
        }
    }

    void OnApplicationQuit() {
        es.Engine.Close();
    }
	
	// Update is called once per frame
	void Update () {
        es.Engine.Dispatch();
	
	}
}

Keep in mind though that the integrated networking is the only way to get peer to peer in the webplayer, anything else requires a central server inbetween that fullfills the security sandbox (security policy handout) requirements

good thing i’m not doing any peer to peer. I put Security.PrefetchSocketPolicy(“192.168.1.105”, 1139); in awake and ran mono sockpol.exe --all on the linux server.

192.168.1.105 is a different machine running the server.

The web player just freezes and i have to kill firefox.

Edit: sockpol.exe doesnt listen on port 1139 does it…

If i take away the Security.PrefetchSocketPolicy(“192.168.1.105”, 1139); and just run the sockpol.exe --all app. Everything works great, can login through web player like a normal standalone. Why is Security.PrefetchSocketPolicy(“192.168.1.105”, 1139); crashing the game in web player mode?

Sockpol.exe seems to respond to port 843 (Unity’s default fetch-policy-port). Where did you get 1139 from?

The webplayer might freeze when the policy server does not respond. It seems to be a blocking call inside Unity and will un-freeze after a timeout (30 or 60 sec). One more reason to avoid servers without policy file hosting.

hmm ill try leave it for a few mins tonight. 1139 is just the default port number the red dwarf server comes with.

Serverside you might want to run sockpol as root… Otherwise it will not be able to listen on ports under 1024 (which you need to listen on port 843). Thus you should run it as follows:

sudo ./sockpol.exe --all
(enter your password)

With the above you should be able to have it listening on port 843. That is my experience at last.