Unity Starts in Web Browser, but cannot connect to webservice.

Started by
5 comments, last by Kylotan 11 years, 1 month ago

I have a Unity 3D game. It connects to a web service, and works great when built as a windows client.

But when I create it as a Web Client, it fails to connect to the web service.

I get this message: " Unable to connect to server, please try again later > [url]"

The graphics still load and display properly in the web client.

The service it is connecting to has the proper cross domain policy file, presumed because the windows client can connect to it.

However, in case that is an issue, here is the file:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

Is there any reason the web client can't connect?

(I get the same results when running the web client from the same server as the service)

Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

Advertisement

What exactly produces the message you mention? Is that in an exception? Is it in the local log? It doesn't sound like any Unity error I've encountered.

You mentioned in your previous post that you're using 'HttpWebClient'. I don't know what this is, exactly. Is this System.Net.WebClient? It may be the case that certain aspects aren't supported. Check here for some function-specific details: http://docs.unity3d.com/Documentation/ScriptReference/MonoCompatibility.html

Is there a reason you're not using Unity's WWW class? That may work where a .Net standard class does not.


What exactly produces the message you mention?

03.11.2013-11.51.png

That is a screen shot from where it tells me. the initial web request is made in a try catch, which caught this error and displayed its message. There was no inner exception.

You mentioned in your previous post that you're using 'HttpWebClient'

Sorry, I misquoted. I'm using HttpWebRequest and HttpWebResponse. According to the list you provided, those work in Web Player.

Is there a reason you're not using Unity's WWW class?

Yes. WWW cannot be run outside of the main thread. I tried it, and it throws an error specifically complaining about not being executed from the main thread.

I have http calls going out to the server quite regularly during game play, and I don't want to lock up the main thread for this data.

Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

BAAAAHHHH!!!! Stupid Documentation. I've been using HttpWebClient, because I read that it was a functional alternative in Unity. In the linl you provided, both http classes I'm using (request and response) are in supported in web player. But the exception I'm getting is System.NotSupportedException. (sorry for any confusion, I found that there was additional text in my code spitting out additional info on the exception, which gave me the original text.

Do you know if there is any reason to get this exception with a feature Unity says should work?

*I'm asking on unity as well.

Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

ok, so it looks like the unity WWW main thread issue, is that alternate threads cannot directly interact with the GameObjects (or on them) There is some confusion surrounding this. so I have some experimenting to do.

Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

Final resolution: I got it working. I used TcpClient and built an Http layer on top of it. That didn't work either at first, so I did more research and installed a Socket Security Policy Service on my server, and now it runs. The demo, the service I used and a better description are all posted on my blog, http://warpwars.blogspot.com/

Thanks for your help in this! :)

Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

Ahh, yes... a lot of the docs are not clear that there are 2 separate ways to notify the client of security settings - the policy file as served up over HTTP (for authorising HTTP access), and a similar file as served directly on a socket (for authorising TCP socket access).

This topic is closed to new replies.

Advertisement