- Home /
External Server Event Unity Web
Hello, From what I've read Unity Web does not allow you to use dlls for security reasons, then, is there any way for an external server (which has not been created from Unity) send some kind of event or message to the application (Unity Web) ?
In desktop app, the way I had to do this was through sockets and a customized dll, but it's not possibloe in unity web so I'm kind of lost.
Any ideas?
Thank you very much!
Answer by Bunny83 · May 02, 2012 at 11:49 AM
You can use Sockets even in the webplayer. However the webplayer can't act as listening socket(server) to accept connections. You can connect to an external server.
Read this page about the security sandbox very carefully. Your server needs to provide a crossdomain policy to allow access to your server. I also recommend to use TCP connections since UDP is connection-less it has to check the policy for each packet that goes out or is comming in. TCP needs to check the policy only when you open the connection.
Answer by sandalia · May 02, 2012 at 03:45 PM
Thank you, I've been checking the security sandbox, but I wonder if it is possible next: the tcp client connects to the server, and after checking the crossdomain policy, the tcp client can read the answer of the server with the Read method, I mean, what I really want is the client waiting all time for answers from the server.
I've tried the SocketPolicyServer located in Tools/SocketPolicyServer that Unity provides you, with the next code for the client:
using UnityEngine; using System.Collections; using System; using System.IO; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; public class ClientTest : MonoBehaviour {
BinaryWriter so;
BinaryReader sr;
// Use this for initialization
void Start () {
TcpClient client = new TcpClient();
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("212.128.171.225"), 843);
client.Connect(serverEndPoint);
NetworkStream clientStream = client.GetStream();
while (!clientStream.CanRead || !clientStream.CanWrite)
{
Debug.Log("Spinning until can write");
}
so = new BinaryWriter(clientStream);
sr = new BinaryReader(clientStream);
so.Write("<policy-file-request/>");
so.Flush();
//Instead of this
Debug.Log(sr.Read());
//We want something like (suppose the server from time to time sends to the client some data)
/*
* for(;;)
* sr.Read();
*/
}
}
Your answer
Follow this Question
Related Questions
How can i receive data from URL like cookies? 0 Answers
Analytic Tool: Get a list of custom user ID for core/custom events. 0 Answers
How to access StartCoroutine in a static way 3 Answers
`Recv failure: Connection was reset` In editor? (platform set to Android NOT WebPlayer) 0 Answers
Developing a server to host a smartphone app content 1 Answer