New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current master doesn't build for Unity web player #52

Open
ssfrr opened this Issue Jun 14, 2014 · 10 comments

Comments

Projects
None yet
4 participants
@ssfrr
Copy link

ssfrr commented Jun 14, 2014

There are some tweaks I had to make in order to get the library to build for the Unity Web Player. I'm not 100% sure how safe the changes are. Most of the issues are API calls that aren't present in the System libraries that the web player gets built with. I'm not using compression or encryption so mostly I just commented out the offending lines to satisfy the compiler.

Assets/Plugins/websocket-sharp/Ext.cs(85,81): error CS1729: The type `System.IO.Compression.DeflateStream' does not contain a constructor that takes `3' arguments

I removed the 3rd argument, also on line 119

Assets/Plugins/websocket-sharp/Net/EndPointListener.cs(172,16): error CS0200: Property or indexer `System.Security.Cryptography.X509Certificates.X509Certificate2.PrivateKey' cannot be assigned to (it is read only)
Assets/Plugins/websocket-sharp/Net/HttpConnection.cs(96,19): error CS1061: Type `WebSocketSharp.Net.Security.SslStream' does not contain a definition for `AuthenticateAsServer' and no extension method `AuthenticateAsServer' of type `WebSocketSharp.Net.Security.SslStream' could be found (are you missing a using directive or an assembly reference?)
Assets/Plugins/websocket-sharp/Net/HttpListenerRequest.cs(242,37): error CS1061: Type `System.Security.Principal.IPrincipal' does not contain a definition for `Identity' and no extension method `Identity' of type `System.Security.Principal.IPrincipal' could be found (are you missing a using directive or an assembly reference?)
Assets/Plugins/websocket-sharp/Net/ListenerAsyncResult.cs(136,22): error CS0117: `System.Threading.ThreadPool' does not contain a definition for `UnsafeQueueUserWorkItem'

This I modified as per https://github.com/kaistseo/UnitySocketIO-WebSocketSharp

Assets/Plugins/websocket-sharp/Net/WebSockets/TcpListenerWebSocketContext.cs(134,39): error CS1061: Type `System.Security.Principal.IPrincipal' does not contain a definition for `Identity' and no extension method `Identity' of type `System.Security.Principal.IPrincipal' could be found (are you missing a using directive or an assembly reference?)
Assets/Plugins/websocket-sharp/Server/HttpServer.cs(676,21): error CS0117: `System.IO.File' does not contain a definition for `ReadAllBytes'
Assets/Plugins/websocket-sharp/WebSocket.cs(1897,33): error CS1061: Type `System.IO.FileInfo' does not contain a definition for `OpenRead' and no extension method `OpenRead' of type `System.IO.FileInfo' could be found (are you missing a using directive or an assembly reference?)
Assets/Plugins/websocket-sharp/WebSocket.cs(1982,38): error CS1061: Type `System.IO.FileInfo' does not contain a definition for `OpenRead' and no extension method `OpenRead' of type `System.IO.FileInfo' could be found (are you missing a using directive or an assembly reference?)
Assets/Plugins/websocket-sharp/WebSocketStream.cs(242,19): error CS1061: Type `WebSocketSharp.Net.Security.SslStream' does not contain a definition for `AuthenticateAsServer' and no extension method `AuthenticateAsServer' of type `WebSocketSharp.Net.Security.SslStream' could be found (are you missing a using directive or an assembly reference?)
@sta

This comment has been minimized.

Copy link
Owner

sta commented Jun 15, 2014

I strongly suggest to build websocket-sharp.dll with MonoDevelop, and use it in Unity.

@ghost

This comment has been minimized.

Copy link

ghost commented Jun 24, 2014

@sta @ssfrr Hi guys, i've started using websocket-sharp and am very pleased with it! Thanks! I have a small issue with the library for the webplayer.

Although when i use the webplayer in the editor, everything works fine, when i build for the actual webplayer, i get a plain error (in the console) saying "Error getting handsake from Socket.IO host instance: An error occurred performing a WebClient request.". No more details.

Currently i'm using the .dll but from what i've heard, .dlls are not compatible with the web player. Could this be the issue? and fyi how can i safely adapt the c# code for my game?

@ghost

This comment has been minimized.

Copy link

ghost commented Jun 24, 2014

@ssfrr have you mannaged to get the webplayer working in the browser?

@ssfrr

This comment has been minimized.

Copy link
Author

ssfrr commented Jun 24, 2014

On @sta's advice I built it in MonoDevelop into a DLL and included the DLL in my Assets folder, and it worked like a charm in both the web and desktop players.

I also thought you couldn't use DLLs in web-player, but I think as long as the DLL is purely managed code (AFAIK basically it just can't call out to native libraries) then it seems to work fine.

Note that the fix in #51 is necessary if you want it to work properly on OSX.

@sta

This comment has been minimized.

Copy link
Owner

sta commented Jun 25, 2014

@badescuga

Although when i use the webplayer in the editor, everything works fine

How did you use websocket-sharp at that time? Copied code or DLL built yourself?

@ghost

This comment has been minimized.

Copy link

ghost commented Jun 26, 2014

@sta copied the dll :) is that not ok? i've built the project and used the resulting dll. I haven't included the fix from #51 but it should still work i think. Note that on top, i'm using socket.io (https://github.com/kaistseo/UnitySocketIO-WebSocketSharp)

@sta

This comment has been minimized.

Copy link
Owner

sta commented Jun 26, 2014

@badescuga

but from what i've heard, .dlls are not compatible with the web player.

I think, perhaps, those .dlls mean unmanaged (native) dlls (, and requires Unity Pro).

websocket-sharp.dll is managed (.NET assembly) dll, so it doesn't apply to the above .dlls.

when i build for the actual webplayer, i get a plain error (in the console) saying "Error getting handsake from Socket.IO host instance: An error occurred performing a WebClient request.".

Have you gotten same error still?

@ghost

This comment has been minimized.

Copy link

ghost commented Jun 26, 2014

@sta yes, still. I have Unity Pro 4.5. I get this error for the requestHandshake. On further debugging (placing while(exception!=null) { Debug.Log("ex: "+ex.Message); e = e.InnerException; }

i also get:

socket client error: SocketIO.Cent.Connect threw an exception

and in the Connect() method:

socket client error: Object reference not set to an instance of an object

@RDeluxe

This comment has been minimized.

Copy link

RDeluxe commented Dec 4, 2014

@badescuga did you find a fix for this ? I am exactly in the same situation. Everything is working fine in the editor (in webplayer mode, with socket policies settled, etc.) but in chrome or firefox I got the same error:

Handshake error stacktrace at System.Net.WebClient.DownloadDataCore (System.Uri address, System.Object userToken) [0x00000] in :0

at System.Net.WebClient.m__E (System.Object state) [0x00000] in :0

Seems to come from this :

byte [] DownloadDataCore (Uri address, object userToken)
{
WebRequest request = null;

        try {
            request = SetupRequest (address);
            return ReadAll (request, userToken);
        } catch (ThreadInterruptedException){
            if (request != null)
                request.Abort ();
            throw new WebException ("User canceled the request", WebExceptionStatus.RequestCanceled);
        } catch (WebException) {
            throw;
        } catch (Exception ex) {
            throw new WebException ("An error occurred performing a WebClient request.", ex);
        }
    }
@rosarionakkocom

This comment has been minimized.

Copy link

rosarionakkocom commented Jun 25, 2016

Just export for webgl, problem solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment