server-side Unity3d Web Player networking configuration

The new game can finish out the first version of the process, I had to admire the skill of the powerful Unity3D, PC, MAC OS, Linux, IOS, Android, web player, just the day before yesterday released unity3d 4.2 version also supports WINDOWS PHONE, Black Barry all these platforms a key package, so easy! But when packaged deploy Web Player, there has been little trouble in terms of networking, which is regarded as so smooth course of an episode of it! So you can write a essay slightly networking configuration for the server side of Unity3d Web Player.
 
  To SmartFoxServer2X official Unity3d Example "tris" for example, after the deployed servers, running in Unity end game is certainly no problem, a successful connection. But when you switch to Web Player packaging, and it is not native to determine the server you connect to, that is - when the server address is not "LocalHost" or "127.0.0.1", you will find a very "interesting" phenomenon (that was not funny anymore troubled brother for a long time _ ~) -! connection is not life and death on the server, either directly in the running game in Unity3D Editor is packed Web Player program to run in the browser. One of the major mistakes described as:
 
[SFS DEBUG] TCPSocketLayer: General exception on connection: Unable to connect, as no valid crossdomain policy was found   at System.Net.Sockets.Socket.Connect_internal (IntPtr sock, System.Net.SocketAddress sa, System.Int32& error, Boolean requireSocketPolicyFile) [0x00000] in <filename unknown>:0 
  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
  After groping access to information that, this is a question Unity WebPlayer Security SandBox mechanism. Unity3D official document to explain the phenomenon: This security restrictions apply only to the webplayer, and to the editor when the active build target is WebPlayer and I encountered the phenomenon description match. It means Unity3d out a mechanism for Web Player security SandBox platform, Only Web Player in security mechanisms, we need a service security policy server configuration when using the Socket. Because there is no any treatment in this area, so the Security SandBox blocked program Socket connection, resulting in the above phenomenon. OK, the problem found.
  The solution is: Unity provides a "sockpol.exe" such a tool, and it has sockpol.exe in "... \ Unity \ Editor \ Data \ Tools \ SocketPolicyServer" path source . If your server is Windows platform, then, a direct Copy sockpol.exe to the server, execute the CMD
 
  
 
sockpol.exe --all
You can configure the Security SandBox security policy server.
 
  Speaking of which, if not carefully read Unity3D official document on Security SandBox is not still a little foggy, can not help asking: the sockpol.exe this is what a wonderful thing it?
 
  OK, we can not read the official document, take a look at the source code sockpol.exe it, just said there sockpol.exe source code under "... \ Unity \ Editor \ Data \ Tools \ SocketPolicyServer" path, from need to connect the port 843 of the server-side source code when it is easy to analyze the original sockpol.exe do live is to monitor Web Player Gets security SandBox platform security policies, monitor when there is a request to port 843, the client sends a request to end a crossdomain.xml configuration, content as a standard crossdomain.xml file formats:
 
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" to-ports="1-65536"/>
</cross-domain-policy>
So that the client will be able to get to the Security SandBox security policies and network activity. Among them, the significance of the implementation of sockpol.exe --all parameter is to set the server's Security SandBox security policy to allow any port to any IP access to the server.
 
  Know this principle, Linux server can easily come to solutions, we use the Linux NetCat (NC) tool to write a script to achieve the same purpose.
 
  First, make sure the Linux server installed NetCat, type 'NetCat' or 'NC' in the SHELL test your system has not been installed this tool. If nothing happens, it is simple, install one.
 
  
 
# If you are using Red Linux or RL line of Linux:
sudo yum install nc
# \ Debian like Linux If you use Ubuntu:
sudo apt-get install nc
After installing the NC, wrote a script:
 
#!/bin/sh
while true; do echo '<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" to-ports="1-65536"/>
</cross-domain-policy>' | nc -l 843; done
Save as serverPolicy.sh
 
Do not forget to get permission to script
 
sudo chmod 755 serverPolicy.sh
 
 
Directly run the script:
 
 
?
1
2
3
sudo ./serverPolicy.sh 
[csharp] view plaincopy
sudo ./serverPolicy.sh

 

 
If there is no error, then, OK, successfully set up Unity3D Web Player Security SandBox platform for server-side security policy. The next test is to do slightly!
 
Yes, direct run this script would be very troublesome, because when the script is also dependent on the SHELL, SHELL or off when we want to do other activities SHELL, the script will stop running. Let method script running in the background:
 
sudo nohup ./serverPolicy.sh &
OK,enjoy!

Guess you like

Origin blog.csdn.net/wwzxbot/article/details/16112665