- Home /
.NET Sockets in the Webplayer?
I read you can use plain .NET Sockets in Unity. Do they also work when the game is running the Browser/Webplayer?
Answer by dannyskim · Feb 28, 2012 at 08:27 PM
In short, yes you can. There are some restrictions ( that shouldn't affect most of what you're doing ) due to the more open nature of web service accessing, so unity implements a socket policy server that is included in the install of Unity I believe. Check here for more in depth information from the Unity Docs:
http://unity3d.com/support/documentation/Manual/Security%20Sandbox.html
"that shouldn't affect most of what you're doing". well, almost ;)
TCP conections work just fine. You need to verify the policy when you establish the connection and are good to go.
UDP on the other hand is a mess! Since UDP is connection-less Unity can't verify a "connection" and therefore Unity will check the policy "every action" which means sending or receiving packets.
To sum up: Never use UDP in the webplayer. TCP is fine but only for outgoing connections. You can't open a listen socket (AFAI$$anonymous$$) in the webplayer. The only way to act as server is to use Unity's builtin RakNet (aka UnityEngine.Network).
Thanks Bunny for the additional info. I was actually using UDP in a side project and I have intent to release in web player. $$anonymous$$ost likely I'll have it run TCP when running on the web and UDP when on mobile.
Your answer
Follow this Question
Related Questions
exception on Webplayer 1 Answer
[MMO - Everquest] How to connect Unity to a non-unity Server? 1 Answer
ASP .NET: How do I link gui components to Unity web player? 0 Answers
.NET Sockets in basic iOS/Android license? 1 Answer
I cant read from the sockets properly - exception 0x80004005: An invalid argument was supplied 2 Answers