- Home /
TCPClient and SslStreams in WebPlayer (C#)
Hello all!
I am writing a module that communicates with an SSL server via a TCPClient
and SSLStream
in C#.
The problem is: it works perfectly in the ViewPort with webplayer presets or in standalone applications, but it does not in the actual Unity WebPlayer.
Although I have a working socket policy server set up and the SSL handshake seems to complete, when writing on the SSLStream, the server receives 0 bytes and the connection closes.
Here is the client code:
TcpClient client = new TcpClient("xxx.xx.xxx.x",xxx);
Debug.Log("Client connected.");
NetworkStream stream = client.GetStream();
SslStream sslStream = new SslStream(
stream,
true,
new RemoteCertificateValidationCallback (ValidateServerCertificate)
);
try
{
sslStream.AuthenticateAsClient("CertificateSigningName",null,System.Security.Authentication.SslProtocols.Ssl3,false);
Debug.Log ("End of handshake");
sslStream.Write(System.BitConverter.GetBytes(someInt),0,4);
}
EDIT: I've been able to see into the webplayer logs that gives me the following output:
SocketPolicyClient1: Incoming GetPolicyStreamForIP
SocketPolicyClient1: About to BeginConnect to xxx.xxx.xxx.xxx:843
SocketPolicyClient1: About to WaitOne
SocketPolicyClient1: Socket connected
Client connected. // This is a log line that I generated, see previous code.
(Filename: C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/WebPlayer/UnityEngineDebug.cpp Line: 54)
Exception: The authentication or decryption has failed. at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
(Filename: C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/WebPlayer/UnityEngineDebug.cpp Line: 54)
Inner exception: Cannot cast from source type to destination type.
This does not happen in the view port. In the Mono Compatibility list, SslStream is supposed to be supported in the web player. Any Idea?
I have found no answer whatsoever. So I changed my protocol because I had control over the server side. For the web player, maybe one could use a javascript plugin in the webpage to use websockets and WSS protocol on a HTTPS web page?