Search Unity

Best HTTP Released

Discussion in 'Assets and Asset Store' started by BestHTTP, Sep 11, 2013.

  1. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    @BestHTTP I don't understand why do you provide us *.csproj files instead of *.asmdef files and let Unity generate *.csproj for us?
     
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @N3uRo

    1. Creating an .asmdef file is a few click, while a .csproj isn't as easy.
    2. Using csproj to generate a dll is backward compatible, I have to support it for Unity 5.x users too.
    3. If there's an .asmdef file, after you import the package you have to do additional steps to make it work (you have to add references to other .asmdef files).
    4. These are just options that you can use, if you want to.
     
  3. TailKitty

    TailKitty

    Joined:
    Nov 23, 2016
    Posts:
    6
    @BestHTTP Not sure if it is Unity or BestHTTP issue, but starting from Unity 2017.3.1f1 BestHTTP can't work for UWP (Tried with 2017.3.1p1-4 and 2018.1.0b13)
    1. By default you can't even build for UWP
    upload_2018-4-19_15-25-24.png
    2. If I set "Don't process" for WSA BestHTTP plugin, then I can build for UWP
    upload_2018-4-19_15-27-19.png
    ... but on runtime I'm getting this error:
    upload_2018-4-19_15-28-10.png

    Here is a small demo project to show an issue: https://1drv.ms/f/s!Aq0cPFNpkUL4bzT6IFnhMz6OpLA

    Can you please help here?
     
    Last edited: Apr 19, 2018
  4. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @TailKitty

    That was one of the main reason why I deprecated the Basic version of the plugin.
    You can upgrade to the Pro version, using it without dlls will compile and will work properly
     
  5. JinhoonKim_dw

    JinhoonKim_dw

    Joined:
    Mar 16, 2018
    Posts:
    2
    Thank you for your response. I was able to identify the main source of overhead with your information - yes, it was cryptography overhead that was limiting maximum speed of download. We are looking for a workaround - including using HTTP instead of HTTPS on CDNs or utilizing native/OS-provided cryptography methods.

    Anyway, I appreciate your support. Please keep up the good work.
     
  6. bradenwade

    bradenwade

    Joined:
    Jan 11, 2015
    Posts:
    2
    Could someone please assist me in an issue i am having with BestHTTP socket IO Emit to namespace. It does not seem to be working. I am able to connect to and listen on the namespace. But cannot emit to the namespace.

    Unity code:
    Code (CSharp):
    1. SocketManager socketManagerHost = new SocketManager(new Uri("http://localhost:3000/socket/socket.io/"), options);
    2. Socket nsp = socketManagerHost.GetSocket("/pchost");
    3. nsp.Emit("host", rc);
    4. socketManagerHost.Open();

    Server side .js :
    Code (JavaScript):
    1. var nsp = io.of('/pchost');
    2. nsp.on('connection', function(socket) {
    3. console.log('new host');
    4.   socket.on('host', function(room) {
    5.     socket.join(room);
    6.     console.log('new host room: '+room);
    7.     });
    8. });

    Executing the code above outputs "new host" to my server console. So i am able to connect to the namespace, but not make it to the "host" emit that would output "new host room: #" to my server console. As soon as i remove the namespace and use the root socket, the host emit works fine. It seems to be that i cannot emit to a namespace, what am i doing wrong?
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @bradenwade

    I think you should Emit when the client already connected:
    Code (CSharp):
    1. SocketOptions options = new SocketOptions();
    2. options.AutoConnect = false;
    3. options.ConnectWith = BestHTTP.SocketIO.Transports.TransportTypes.WebSocket;
    4.  
    5. SocketManager socketManager = new SocketManager(new Uri("http://localhost:3000/socket.io/"), options);
    6. Socket nsp = socketManager.GetSocket("/pchost");
    7.  
    8. nsp.On(SocketIOEventTypes.Connect, (socket, packet, args) =>
    9. {
    10.     nsp.Emit("host", rc);
    11. });
    12.  
    13. socketManager.Open();
     
  8. bradenwade

    bradenwade

    Joined:
    Jan 11, 2015
    Posts:
    2
    That did the trick! My life is now complete!!! Thanks
     
    Last edited: Apr 27, 2018
  9. UglyDuckling

    UglyDuckling

    Joined:
    Mar 18, 2015
    Posts:
    10
    Hi, first, thanks for creating and supporting this great asset.

    I'm currently developing a mutliplayer game using the SignalR components. The server is currently implemented in ASP.NET Core 2.1 Preview 2.

    When I try to connect to my server I get this error:
    Err [NegotiationData]: Negotiation request failed with error: Negotiation request finished Successfully, but the server sent an error. Status Code: 405-Method Not Allowed Message:  Uri: http://localhost:5000/signalr/game/negotiate?tid=0&_=2348279174&clientProtocol=1.5&connectionData=[{"Name":"game"}]


    When googling the error I found this:
    https://neelbhatt.com/2018/03/09/so...-method-not-allowed-net-core-errors-part-iii/

    Does this mean that the SignalR implementation changed and to support the new version in ASP.NET Core 2.1 you first have to add support for the new "protocol"?

    ... or am I doing something wrong? =)
     
  10. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @UglyDuckling

    You are correct, that article you linked is just spot on.
    However, the plugin has a SignalR Core implementation too, but it's in a preview state too. It has no documentation or samples.
     
  11. UglyDuckling

    UglyDuckling

    Joined:
    Mar 18, 2015
    Posts:
    10
    Okey, thank you for your quick reply.

    Seems like everytime I try to implement something using .NET I run into these kind if issues. They are developing new stuff to fast. =)

    Is there a way to enable the SignalR Core preview support in Best HTTP? Or is it better to revert to and older version of SignalR... or replace it with pure WebSockets? If I don't remember wrong I think the new version of ASP.NET Core has support for pure websockets.
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @UglyDuckling

    Sent the latest version of the protocol in a private message.

    I'm unsure about a recommendation. The old SignalR isn't maintained by now afaik, the new one is just new, and websocket is low-level. :D
     
    UglyDuckling likes this.
  13. WilsonOnPoint

    WilsonOnPoint

    Joined:
    Nov 4, 2017
    Posts:
    2
    Hi, I get this error everytime I receive an event with Socket.IO. Could anyone help me? I'm kinda getting clueless at what to do

    Ex [EventDescriptor]: Call - Message: 1: Object reference not set to an instance of an object at Login.SaveAuthKey (BestHTTP.SocketIO.Socket socket, BestHTTP.SocketIO.Packet packet, System.Object[] args) [0x0000f] in D:\Game\Unity Project\Driver\Assets\Scripts\Network\Login.cs:61
    at BestHTTP.SocketIO.Events.EventDescriptor.Call (BestHTTP.SocketIO.Socket socket, BestHTTP.SocketIO.Packet packet, System.Object[] args) [0x00067] in D:\Game\Unity Project\Driver\Assets\Best HTTP (Pro)\BestHTTP\SocketIO\Events\EventDescriptor.cs:73 StackTrace: at Login.SaveAuthKey (BestHTTP.SocketIO.Socket socket, BestHTTP.SocketIO.Packet packet, System.Object[] args) [0x0000f] in D:\Game\Unity Project\Driver\Assets\Scripts\Network\Login.cs:61
    at BestHTTP.SocketIO.Events.EventDescriptor.Call (BestHTTP.SocketIO.Socket socket, BestHTTP.SocketIO.Packet packet, System.Object[] args) [0x00067] in D:\Game\Unity Project\Driver\Assets\Best HTTP (Pro)\BestHTTP\SocketIO\Events\EventDescriptor.cs:73
    UnityEngine.Debug:LogError(Object)
    BestHTTP.Logger.DefaultLogger:Exception(String, String, Exception) (at Assets/Best HTTP (Pro)/BestHTTP/Logger/DefaultLogger.cs:111)
    BestHTTP.SocketIO.Events.EventDescriptor:Call(Socket, Packet, Object[]) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/Events/EventDescriptor.cs:79)
    BestHTTP.SocketIO.Events.EventTable:Call(String, Packet, Object[]) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/Events/EventTable.cs:84)
    BestHTTP.SocketIO.Events.EventTable:Call(Packet) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/Events/EventTable.cs:106)
    BestHTTP.SocketIO.Socket:BestHTTP.SocketIO.ISocket.OnPacket(Packet) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/Socket.cs:409)
    BestHTTP.SocketIO.SocketManager:BestHTTP.SocketIO.IManager.OnPacket(Packet) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/SocketManager.cs:539)
    BestHTTP.SocketIO.Transports.PollingTransport:OnPacket(Packet) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/Transports/PollingTransport.cs:334)
    BestHTTP.SocketIO.Transports.PollingTransport:parseResponse(HTTPResponse) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/Transports/PollingTransport.cs:423)
    BestHTTP.SocketIO.Transports.PollingTransport:OnPollRequestFinished(HTTPRequest, HTTPResponse) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/Transports/PollingTransport.cs:270)
    BestHTTP.HTTPRequest:CallCallback() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPRequest.cs:1267)
    BestHTTP.ConnectionBase:HandleCallback() (at Assets/Best HTTP (Pro)/BestHTTP/Connections/ConnectionBase.cs:173)
    BestHTTP.HTTPManager:OnUpdate() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPManager.cs:598)
    BestHTTP.HTTPUpdateDelegator:Update() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPUpdateDelegator.cs:178)
     
  14. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @WilsonOnPoint

    You should check out what happens in your Login.cs at line 61 because a NullReferenceException is happening there.
     
  15. WilsonOnPoint

    WilsonOnPoint

    Joined:
    Nov 4, 2017
    Posts:
    2
    @BestHTTP WOW! Thanks, I must have been too tired to not see that. Been trying for hours hahaha! Thanks for the super fast reply!!
     
  16. RazaTech

    RazaTech

    Joined:
    Feb 27, 2015
    Posts:
    178
    Last edited: May 3, 2018
  17. Brightline

    Brightline

    Joined:
    Apr 14, 2014
    Posts:
    7
    What's the best method to manually force a disconnect and reconnect on Socket.IO? When the internet connection changes, Socket.IO doesn't seem to recover correctly and attempt to reconnect in a timely manner. My testing was with a timeout of 3, turning on and off a VPN. Restarting the app (or hitting play in Unity) resolved the connection.
     
  18. dron_megatron

    dron_megatron

    Joined:
    Sep 8, 2017
    Posts:
    1
    Hello!

    I got issue with images loading when I upgraded project from Unity 5.6 to Unity 2018. In 5.6 everything was perfect, but in 2018 I have big delay when loading pictures. Some data loads fast, some stucks for several seconds and then loads Ok. I can give full log. But maybe my issue is already solved?

    At the application start I use some settings:
    Code (CSharp):
    1.  
    2.             HTTPManager.MaxConnectionIdleTime = TimeSpan.FromSeconds(10);
    3.             HTTPManager.KeepAliveDefaultValue = false;
    4.             HTTPManager.UseAlternateSSLDefaultValue = false;
     
  19. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @RazaTech

    Could you share what's errors/issues are you see?

    This code worked perfectly:
    Code (CSharp):
    1. Uri uri = new Uri("http://jcboston.org/?feed=podcast");
    2.  
    3. HTTPRequest request = new HTTPRequest(uri, (req, resp) =>
    4. {
    5.     switch (req.State)
    6.     {
    7.         // The request finished without any problem.
    8.         case HTTPRequestStates.Finished:
    9.             if (resp.IsSuccess)
    10.             {
    11.                 Debug.Log("Request Finished Successfully! Response: " + resp.DataAsText);
    12.             }
    13.             else // Internal server error?
    14.                 Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    15.                                                 resp.StatusCode,
    16.                                                 resp.Message,
    17.                                                 resp.DataAsText));
    18.             break;
    19.  
    20.         // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    21.         case HTTPRequestStates.Error:
    22.             Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    23.             break;
    24.  
    25.         // The request aborted, initiated by the user.
    26.         case HTTPRequestStates.Aborted:
    27.             Debug.LogWarning("Request Aborted!");
    28.             break;
    29.  
    30.         // Connecting to the server is timed out.
    31.         case HTTPRequestStates.ConnectionTimedOut:
    32.             Debug.LogError("Connection Timed Out!");
    33.             break;
    34.  
    35.         // The request didn't finished in the given time.
    36.         case HTTPRequestStates.TimedOut:
    37.             Debug.LogError("Processing the request Timed Out!");
    38.             break;
    39.     }
    40. });
    41.  
    42. request.Send();
     
  20. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @UnityBLI

    You can let the plugin that it shouldn't try to reconnect, you want to handle it manually:
    Code (CSharp):
    1. SocketOptions options = new SocketOptions();
    2. options.Reconnection = false;
    3.  
    4. var manager = new SocketManager(new Uri("http://localhost:3000/socket.io/"), options);
    5.  
    6. manager.Socket.On(SocketIOEventTypes.Disconnect, (s, p, a) =>
    7. {
    8.     (manager as IManager).TryToReconnect();
    9. });
    You can call TryToReconnect manually, or do any other logic there.
     
  21. Brightline

    Brightline

    Joined:
    Apr 14, 2014
    Posts:
    7
    I like the reconnect logic as it stands, but the issue is that it's not detecting a disconnect possibly due to the network change. I have a separate http request that is checking online status against google.com every 3 seconds, and when the internet is detected as down (during the network switch), I disable internet-connected parts of my app. When the internet is detected as up again using that separate process, I want to cycle the socket.io connection.

    So I guess my question is, is there a way to force a disconnect while leaving the existing reconnection logic intact?
     
  22. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @UnityBLI

    Hmm, you can try out the following:

    • Any time when you want to close:
    Code (CSharp):
    1. manager.Options.Reconnection = false;
    2. (manager as IManager).Close(false);
    • And later when you want to try to reconnect:
    Code (CSharp):
    1. manager.Options.Reconnection = true;
    2. (manager as IManager).TryToReconnect();
     
  23. Brightline

    Brightline

    Joined:
    Apr 14, 2014
    Posts:
    7
    These do not seem to work to kickstart the network in the case of a network change. Is it possible that BestHTTP is caching some network settings at a lower level, which is not allowing socket.io to reconnect correctly? If that is the case, is there a way to completely reset BestHTTP's network settings and start fresh?

    Also, if I call Manager.Close, should I expect to see a Disconnect event?
     
  24. andychan0704

    andychan0704

    Joined:
    Nov 8, 2016
    Posts:
    2
    Hi, may I know if BestHTTP's socketIO supports background processing? It seems that ping-pong handshake will be stopped when the app was switched to background and resumed to foreground after the ping timeout value, say 10sec (in Unity iOS's build setting, "Background fetch" was enabled). As a result, server was disconnected. Thanks
     
  25. esoinila

    esoinila

    Joined:
    Apr 27, 2017
    Posts:
    8
    I had a similar experience with Web-Socket (that Socket.IO is using according to the manual). I could replicate it even with the provided sample. First start the websocket-sample. Send couple messages. Then cut off the net (with airplane mode or by other means like closing mobile-wifi-hotspot at hotspot end). Click to send couple more times. Soon you get this :
    W [WebSocketResponse]: No message received in the given time! Closing WebSocket. LastMessage: 5/4/2018 9:49:23 AM, PingFrequency: 00:00:01, Close After: 00:00:10, Now: 5/4/2018 9:49:34 AM

    But this disconnect does not set the websocket connection to null, unlike the manual disconnect. After this it seems to be impossible to reconnect even after network has been restored, without reloading the scene etc.. Or in the Sample selector going back and re-entering the example. (image is available at http://soinila.fi/timeoutDisconnectIssue.jpg)
     
    Last edited: May 4, 2018
  26. esoinila

    esoinila

    Joined:
    Apr 27, 2017
    Posts:
    8
    Looks like, if I set the
    webSocket = null; // Brute force test
    Then I can reconnect again after timeout (sabotaged connection).
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    Fixed a bug, but could initiate a conversation only with @esoinila to send a new package. @UnityBLI you can enable private messages on this forum or you can reach me in email.
     
  28. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @andychan0704

    On mobile platforms Unity will pause itself when goes to background, so most of the plugin's logic will be paused/stopped too.
    The underlying OS has the right to close the app's TCP connections too.
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @dron_megatron

    Sorry for the late reply!

    I do not know any issues or delays processing images. The plugin itself doesn't do any specific for images, it just provides a quick shortcut to convert the downloaded bytes into a Unity texture:
    Code (CSharp):
    1. /// <summary>
    2. /// The data loaded to a Texture2D.
    3. /// </summary>
    4. public Texture2D DataAsTexture2D
    5. {
    6.     get
    7.     {
    8.         if (Data == null)
    9.             return null;
    10.  
    11.         if (texture != null)
    12.             return texture;
    13.  
    14.         texture = new Texture2D(0, 0, TextureFormat.ARGB32, false);
    15.         texture.LoadImage(Data);
    16.  
    17.         return texture;
    18.     }
    19. }
    This creates the texture only when you try to access it. The algorithm behind the LoadImage might changed between Unity 5.6 and 2018.
     
  30. shb

    shb

    Joined:
    Oct 7, 2012
    Posts:
    23
    I have 2 issues

    1. Lastest Best HTTP socket.io doesn't work on Unity2018.1.0f2
    Sample Socket.io failed with array index is out of range error.
    my socket.io server version is v2.0.4

    works fine with previous version of BestHTTP.

    2. BestHttp doesn't work with latest socket.io server (v.2.1.0)
    it keeps connecting and disconnecting every few seconds.
    If I use socket.io v.2.0.4 on my server, BestHttp works fine.
     

    Attached Files:

  31. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @shb

    What version of the plugin are you using? The latest one should fix the reconnect issue. (The first issue should be related to the old plugin version too, it works fine with the latest Unity too.)
     
  32. esoinila

    esoinila

    Joined:
    Apr 27, 2017
    Posts:
    8
    The patch seems to work nicely.:)
     
  33. Ginxx009

    Ginxx009

    Joined:
    Sep 11, 2016
    Posts:
    89
    Hello BestHTTP could i ask if what i am doing wrong in my code
    Code (CSharp):
    1. [SerializeField] GameObject[] uitex = new GameObject[4];
    2.  
    3. for (int i = 0; i < tzPlayInfo.Instance.bc_gametablelist.Count; i++)
    4.         {
    5.             dealer_img += tzPlayInfo.Instance.bc_gametablelist[i].dlrimage;
    6.  
    7.             new BestHTTP.HTTPRequest(new System.Uri("********************.amazonaws.com/resources/" + "dealer/pic/" + dealer_img),
    8.             (BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse res)
    9.             =>
    10.             {
    11.                 var tex = new Texture2D(20, 20);
    12.                 tex.LoadImage(res.Data);
    13.                 uitex[i].GetComponent<UITexture>().mainTexture = tex;
    14.             }).Send();
    15.         }
    It's giving me an Array index is out of range. StackTrace .
     
  34. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @PaulKevin

    I'm not sure, but i think you are receiving that error indexing uitext in the callback. You can try something like this:
    Code (CSharp):
    1. for (int i = 0; i < tzPlayInfo.Instance.bc_gametablelist.Count; i++) {
    2.   dealer_img += tzPlayInfo.Instance.bc_gametablelist[i].dlrimage;
    3.  
    4.   var request = new BestHTTP.HTTPRequest(new System.Uri("********************.amazonaws.com/resources/" + "dealer/pic/" + dealer_img),
    5.     (BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse res)
    6.     => {
    7.       var tex = new Texture2D(20, 20);
    8.       tex.LoadImage(res.Data);
    9.  
    10.       UITexture uiTexture = req.Tag as UITexture;
    11.       if (uiTexture != null)
    12.         uiTexture.mainTexture = tex;
    13.     });
    14.  
    15.   if (i < uitex.Length)
    16.     request.Tag = uitex[i].GetComponent<UITexture>().mainTexture;
    17.   request.Send();
     
  35. andychan0704

    andychan0704

    Joined:
    Nov 8, 2016
    Posts:
    2
    Thanks for your reply. Noted. It will be good if you can enable the plugin running in background (in order to keep the Host connect alive) via some configuration in future version. Otherwise, seems that the only way is to reconnect the Host after connection timeout. Cheers.
     
  36. Ginxx009

    Ginxx009

    Joined:
    Sep 11, 2016
    Posts:
    89
    Its okay now . Thanks for replying. Sorry didn't get back instantly when the code runs
     
  37. AG_Dan

    AG_Dan

    Joined:
    Jul 31, 2017
    Posts:
    6
    I recently updated to the latest BestHTTP Pro version and am having an issue with WebSockets. If the socket connection gets disrupted (say by rebooting the server that it is connected to), the WebSocket object is internally closed as expected, but in the latest version of the library it no longer fires any of the events that my code is subscribed to (ie: OnError/OnClosed). My application is then unaware that anything has gone wrong, and all subsequent calls to Send() silently fail as the first line of the Send() method checks if the connection is open.
     
  38. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @AG_Dan

    Sent a download link in a private message.
     
  39. reddy36996

    reddy36996

    Joined:
    Jan 10, 2016
    Posts:
    19
    Hi @BestHTTP
    I'm using "5.0.1 Best HTTP (Pro) 1.9.17 Beta" and Unity 2017.3.1f1
    In my new project, i am getting below error every so often, after that SignalR connection is closed. Let me know if any more details are needed.

    Err [SignalR Connection]: EventSource Closed!
    UnityEngine.Debug:LogError(Object)
    BestHTTP.Logger.DefaultLogger:Error(String, String) (at Assets/ThirdPartyPlugins/Best HTTP (Pro)/BestHTTP/Logger/DefaultLogger.cs:76)
    BestHTTP.SignalR.Connection:BestHTTP.SignalR.IConnection.Error(String) (at Assets/ThirdPartyPlugins/Best HTTP (Pro)/BestHTTP/SignalR/Connection.cs:835)
    BestHTTP.SignalR.Transports.ServerSentEventsTransport:OnEventSourceError(EventSource, String) (at Assets/ThirdPartyPlugins/Best HTTP (Pro)/BestHTTP/SignalR/Transports/ServerSentEventsTransport.cs:156)
     
  40. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi there! I'am trying example from the docs
    Code (CSharp):
    1.  
    2. var request = new HTTPRequest(new Uri(CommonSettings.Instance.assetBundlesURL + model.clipName.ToLower() + ".mp3"), (req, resp) => {
    3.     List<byte[]> fragments = resp.GetStreamedFragments();
    4.  
    5.     // Write out the downloaded data to a file:
    6.     using (FileStream fs = new FileStream(fileName, FileMode.Append))
    7.         foreach (byte[] data in fragments)
    8.             fs.Write(data, 0, data.Length);
    9.  
    10.     if (resp.IsStreamingFinished)
    11.     {
    12.         Debug.Log("LoadAssetBundle Download finished!");
    13.         /*onTrackLoaded(null, true);
    14.         ClipPlayer.Instance.Play(fileName, true);*/
    15.         //resp.Dispose();
    16.     }
    17. });
    18. request.UseStreaming = true;
    19. request.StreamFragmentSize = 1 * 1024 * 1024; // 1 megabyte
    20. request.DisableCache = true; // already saving to a file, so turn off caching
    21. request.Send();
    22.  
    In Editor it works fine, but on Android i have an error

    CallCallback - Message: 1: Object reference not set to an instance of an object at TrackLoadingManager+<LoadAssetBundleCor>c__AnonStorey4.<>m__0 (BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse resp) [0x00017] in C:\Unity_Projects\JamTracks\Assets\Scripts\TrackLoadingManager.cs:245
    at BestHTTP.HTTPRequest.CallCallback () [0x0001a] in C:\Unity_Projects\JamTracks\Assets\Best HTTP (Pro)\BestHTTP\HTTPRequest.cs:1255 StackTrace: at TrackLoadingManager+<LoadAssetBundleCor>c__AnonStorey4.<>m__0 (BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse resp) [0x00017] in C:\Unity_Projects\JamTracks\Assets\Scripts\TrackLoadingManager.cs:245
    at BestHTTP.HTTPRequest.CallCallback () [0x0001a] in C:\Unity_Projects\JamTracks\Assets\Best HTTP (Pro)\BestHTTP\HTTPRequest.cs:1255

    (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

    So it's points on this line
    Code (CSharp):
    1.  foreach (byte[] data in fragments)
     
  41. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,945
    @BestHTTP

    Can i use BestHTTP to load files saved in Application.persistentDataPath?

    2- can i use BestHTTP to load files from Resources? as using Resources.LoadAsync require coroutine which generate garbage.

    Update:
    3- Can i use it to load from streamingassets?
     
    Last edited: May 13, 2018
  42. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @reddy36996

    First I would try to update the package, 1.9.17 is more than one year old.
     
  43. reddy36996

    reddy36996

    Joined:
    Jan 10, 2016
    Posts:
    19
    I tried upgrading package after every new release, but same error comes when i try to connect signalR hub on webGL, It is fine on Android/ios though, Error says something about "eventname not defined". Even 1.9.17 version had the same issue, you provided to me beta version at that time after fixing that issue. But once upgraded, same error comes again so i haven't try upgrading it recently. I will give it a try then.
     
  44. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @reddy36996

    Yes, there was a bug in the WebGL jslib, but it's fixed by now. I can't find in the release notes, so i don't know exactly when it has been fixed, but as I remember it was after 1.10.1.
     
  45. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @justtime

    The code in the documentation is a very streamlined version, it has no error checking. For a more complete example i would recommend to check out the LargeFileDownloadSample.cs in the \Best HTTP (Pro)\Examples\HTTP\ folder.

    Anyway, the concrete problem here is that GetStreamedFragments can return with a null value when nothing downloaded yet between two GetStreamedFragments call.
     
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @AmRafay1

    There's a minimal file:// protocol support in the plugin, but it can load files that can be accessed with normal file operations (so it can't read files from the apk on android).
    So, it's a yes for your first question, and a maybe for streaming assets.
    I think you still have to use Resources.Load for resources.
     
  47. reddy36996

    reddy36996

    Joined:
    Jan 10, 2016
    Posts:
    19
    Just updated it and ported the project in webGL, that bug is not happening anymore. As for "Err [SignalR Connection]: EventSource Closed!", i'll observe the build for some time to confirm if it is resolved.
    Thanks
     
  48. conigliocattivo

    conigliocattivo

    Joined:
    May 14, 2013
    Posts:
    10
    Hello there!
    Is there a way to trigger and handle background downloads in Android with BestHTTP?

    Thanks,
    Antonio
     
  49. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @conigliocattivo

    No, sorry. The plugin uses the plain c# Socket class, there's no platform specific feature set.
     
  50. conigliocattivo

    conigliocattivo

    Joined:
    May 14, 2013
    Posts:
    10
    Got it, thanks!