Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Best HTTP Released

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

  1. theferfactor

    theferfactor

    Joined:
    Dec 16, 2016
    Posts:
    4
    Hi, @BestHTTP I tried the Socket.io chat demo and it only shows connecting, could you explain why?
    I would like to get this asset mainly for the Socket.io feature on Webgl, so I want to be sure it works.
    Thanks.
     
  2. roointan

    roointan

    Joined:
    Jan 8, 2018
    Posts:
    46
    Hi @BestHTTP


    We are using BestHTTP to communicate with a backend server over Websockets.
    Sometimes, on iOS, the connection stops working, but the client software will need to wait for the server to close the connection and report an event. No event (Error or Close) is triggered automatically by BestHTTP.

    I see examples of this log when this situation happens:
    2020-05-01 12:26:36.829220+0200 quickcheckers[4674:1053237] Connection 18: encountered error(1:53)
    2020-05-01 12:26:36.851089+0200 quickcheckers[4674:1053237] Connection 11: encountered error(1:53)
    2020-05-01 12:26:36.878281+0200 quickcheckers[4674:1053237] Connection 7: encountered error(1:53)

    So the underlying OS is reporting something. I don't know why doesn't BestHTTP catch them.
    Can you help fix this issue?
     
  3. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @theferfactor

    The plugin tries to connect to the official chat sample(https://socket-io-chat.now.sh), but it's not working now. With default settings, the plugin tries to reconnect until it succeeds, that's why it show only that it's connecting.
     
  4. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @roointan

    The plugin can detect disconnected tcp channels only when it tries to write to them and instead of a succesfull operation, it throws an exception. If Unity's IL2CPP implementation or the OS let the plugin just write and write to the channel without erroring, the plugin can't do anything.

    If you have infrequent writes, you can turn on websocket's StartPingThread and change PingFrequency to a lower value.
     
  5. theferfactor

    theferfactor

    Joined:
    Dec 16, 2016
    Posts:
    4
    Alright, Thanks.
     
  6. vzheng

    vzheng

    Joined:
    Dec 4, 2012
    Posts:
    41
    Hi, this is my picture url: http://39.105.207.202:8011/ssp/material/20200508/formalQD0600001820200508215802133.jpg
    and i dont know why it failed;

    is it too big?
    or is there a way to setting for big texture?

    my code here:
    Code (CSharp):
    1.     public void DownloadImage(string url, Action<Texture2D> OnFinishedDownload)
    2.     {
    3.         new HTTPRequest(new Uri(url), (request, response) =>
    4.         {
    5.             var tex = new Texture2D(0, 0);
    6.             tex.LoadImage(response.Data);
    7.             OnFinishedDownload?.Invoke(tex);
    8.         }).Send();
    9.     }
    And when it run, i got a red question mark
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @vzheng

    Just tried out and worked as it should (didn't displayed it checked only for succesful download).
    What you see as failed? Is it possible that it could download but Unity's LoadImage couldn't load it? If the download fails, could you capture full logs and send it to me?
     
  8. vzheng

    vzheng

    Joined:
    Dec 4, 2012
    Posts:
    41
    hi, is this way to send you the logs?
    or some files?
    upload_2020-5-11_17-37-27.png
     
  9. vzheng

    vzheng

    Joined:
    Dec 4, 2012
    Posts:
    41
    upload_2020-5-11_17-38-34.png

    this is the texture
     
  10. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @vzheng

    It seems that LoadImage couldn't load the image. You might try to save it with different options.
     
  11. roointan

    roointan

    Joined:
    Jan 8, 2018
    Posts:
    46
    When using BestHTTP for Websocket, does it run on a separate thread?
    Any chance for webSocket.OnMessage handler to be running on a thread other than main thread?
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @roointan

    Sending and receiving are done on separate threads, but callbacks are called on Unity's main thread. While setting HTTPUpdateDelegator.IsThreaded going to call callbacks from a thread too, I would suggest to remeain on Unity's main thread and use ThreadPool to do time consuming processing you would do normally in your callback.
     
    roointan likes this.
  13. roointan

    roointan

    Joined:
    Jan 8, 2018
    Posts:
    46
    Thanks so much @BestHTTP
    Another question. Is it possible to force webSocket.OnMessage handler codes run even when app is in background?
    We need to support both Android and iOS
     
    Last edited: May 12, 2020
  14. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @roointan

    Last time i checked threads are still running while the app is in the background. At least under android, i don't know about ios.
    So, when the app goes to the background you can fire up a thread and call HTTPManager.OnUpdate(); manually. That would help keeping connections alive and callbacks would be called, but it would bring its own new problems (thread synchronization, you can access a very restricted set of unity apis).
     
    roointan likes this.
  15. OdedEisenPixi

    OdedEisenPixi

    Joined:
    Aug 27, 2019
    Posts:
    7
    @BestHTTP
    Hi,
    SignalR core question - when disconnection the network (like turning off the wifi during gameplay) - is there a way to detect it?
    We're not using streaming, and even using Invoke - the OnError is not called.
     
  16. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @OdedEisenPixi

    It's going to detect it, but it can take a little time. To detect a broken connection the client have to send messages. You can try to fine tune HubOption's PingInterval value by setting it to lower.
     
  17. OdedEisenPixi

    OdedEisenPixi

    Joined:
    Aug 27, 2019
    Posts:
    7
    @BestHTTP
    I got a strange result:
    We use 2 hubs - one for chat (with the default PingInterval) and one for a mini-game (which I changed the PingInterval to 3 seconds).
    After I turn off the wifi, the chat take s about a minute to detect the disconnection, and the mini-game after another minute (almost 2 minutes in total).
    I guess this is not the expected outcome
    Also - if I use Invoke<>, and the internet is down, how long until the OnError is called, if at all? (The OnError wasn't called on my case)
     
  18. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @OdedEisenPixi

    Not all writes result in an error if the underlying OS fails to send the message. Sending messages are non-blocking operations, send only puts the message into the write buffer it doesn't wait until delivered (or fail to do so).
    So, while propagating back the connection error can take time, minutes seems to be a little too long. I tried out on two different devices and it was pretty quick. It would be helpful if you could set the plugin's log level to All and send all the logs to me.
     
  19. joy901

    joy901

    Joined:
    Jan 12, 2019
    Posts:
    1
    I am using Unity 2017.4.x version and .Net 3.x version . Here it work well.
    But it does not work with .Net 4.x version. It is always getting reconnecting message. Any solution?
     
  20. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @joy901

    Just tried out and it worked as expected. Could you send me full logs?
     
  21. mmvlad

    mmvlad

    Joined:
    Dec 31, 2014
    Posts:
    92
    @BestHTTP
    Hello, I am trying to do a custom retry request with async/await , and after first failed request I keep getting an error:

    Remote server closed the connection before sending response header! Previous request state: Processing. Connection state: Processing

    The code looks like this (I am recreating request every time mostly because it is easier, as I am having a custom request/response classes, and best HTTP is used as transport, if there is a good point to reusing the request please let me know)


    Code (CSharp):
    1. for (i = 0 to MaxRetries) {
    2.     await Task.Delay(_retryPause);
    3.  
    4.     Request = new Request(POST);
    5.     AddHeaders();
    6.  
    7.     try
    8.     {
    9.         var response = await Request.GetHTTPResponseAsync();
    10.         if (response.IsSuccess)
    11.         {
    12.             return response;
    13.         }
    14.      
    15.         if (response.StatusCode == 401)
    16.         {
    17.             await _tokenUpdateFunc();
    18.         }
    19.     }
    20.     catch (Exception e)
    21.     {
    22.         // log error
    23.     }
    24. }
     
  22. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @mmvlad

    Could you send a full log to my email address (besthttp@gmail.com)?
     
  23. mmvlad

    mmvlad

    Joined:
    Dec 31, 2014
    Posts:
    92
    Thank you, but fortunately I found out what was the problem right after I posted the question. I was using Flask local server and it had problems with keep alive. After disabling keep alive for editor builds it worked like a charm.
     
  24. ChristopherWathen

    ChristopherWathen

    Joined:
    Dec 24, 2019
    Posts:
    1
    Running into some issues with deserialization in my current setup. I'm using Azure functions + server-less SignalR and trying to serialize an object with message pack, send payload to function via HTTP request then pass the object back to all the connected clients in a SignalR message argument. Everything works as far as I can tell up to a certain point...I'm able to deserialize the object in my Azure function code using message pack and display the correct result. Whenever the message hits the client, however I get the following:

    Code (CSharp):
    1. [637292802579147850] Ex [WebSocketTransport]: OnMessage(byte[]) - Message: 1: Unexpected token readed 'EndOfArray' while 'BeginArray' is expected.   at GameDevWare.Serialization.Serializers.ArraySerializer.Deserialize (GameDevWare.Serialization.IJsonReader reader) [0x00052] in /Users/christopherwathen/Desktop/Projects/Tellus/Assets/Plugins/GameDevWare.Serialization/Serializers/ArraySerializer.cs:60
    After looking into the server-less signalR documentation I found this : "The performance of Azure SignalR Service is not sensitive to protocols because it doesn't decode the message payload during message forwarding from clients to servers or vice versa." so my assumption is that maybe the client deserialization process is expecting something to be added to the payload that isn't getting added due to server-less SignalR?

    I'm new to most of this stuff so sorry if i'm missing something silly.
     
  25. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @ChristopherWathen I would recommend to switch back to the json encoder first, to see whether it works that way and you can progress. Later you can still add the new encoder.
    I'm going to check it out what's going on.
     
  26. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,045
    Hi @BestHTTP
    I just downloaded latest version and tried making a simple post request and getting this error instanatly, any idea?

    Update 2:
    I also disabled BESTHTTP_DISABLE_HTTP2
    but still same issue

    Update 3:
    using UnityWebRequest works fine.


    Code (CSharp):
    1. {"tid":1,"div":"RequestEventHelper","msg":"HandleRequestStateChange ConnectionTimedOut","ex": [{"msg": "Object reference not set to an instance of an object", "stack": "  at ARrow.ScreenDynamicSimple+<>c.<Start>g__Handler|7_0 (BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse response) [0x00008] in ASamWeb\\Scripts\\ScreenDynamicSimple.cs:67 \r\n  at BestHTTP.Core.RequestEventHelper.HandleRequestStateChange (BestHTTP.Core.RequestEventInfo event) [0x001d4] in Best HTTP\\Source\\Core\\RequestEvents.cs:313 "}],"stack":"  at Core.RequestEventHelper.HandleRequestStateChange (Core.RequestEventInfo event) [0x001fc] in Best HTTP\\Source\\Core\\RequestEvents.cs:317 \r  at Core.RequestEventHelper.ProcessQueue () [0x002ef] in Best HTTP\\Source\\Core\\RequestEvents.cs:221 \r  at HTTPManager.OnUpdate () [0x00001] in Best HTTP\\Source\\HTTPManager.cs:374 \r  at HTTPUpdateDelegator.Update () [0x00020] in Best HTTP\\Source\\HTTPUpdateDelegator.cs:171 ","ctxs":[{"TypeName": "HTTPRequest", "Hash": 117645824}],"t":637296407222582368,"ll":"Exception","bh":1}
    2. UnityEngine.Debug:LogError(Object)
    3. BestHTTP.Logger.UnityOutput:Write(Loglevels, String) (at Assets/Best HTTP/Source/Logger/UnityOutput.cs:22)
    4. BestHTTP.Logger.ThreadedLogger:WriteToOutput(LogJob) (at Assets/Best HTTP/Source/Logger/ThreadedLogger.cs:107)
    5. BestHTTP.Logger.ThreadedLogger:ThreadFunc() (at Assets/Best HTTP/Source/Logger/ThreadedLogger.cs:121)
    6. BestHTTP.PlatformSupport.Threading.<>c__DisplayClass5_0:<RunLongLiving>b__0(Object) (at Assets/Best HTTP/Source/PlatformSupport/Threading/ThreadedRunner.cs:98)
    7. System.Threading.ThreadHelper:ThreadStart(Object)
    8.  
     
    Last edited: Jul 6, 2020 at 10:49 AM
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
  28. leaverforyou

    leaverforyou

    Joined:
    Mar 21, 2020
    Posts:
    1
    Hi @BestHTTP
    There are many unsolvable exceptions in our APP,We need your help!!
    Code (CSharp):
    1.  
    2. AggregateException
    3.  
    4. One or more errors occurred. ***Exception: One or more errors occurred.
    5.  StackTrace: at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00000] in <00000000000000000000000000000000>:0
    6. at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0
    7. at System.Net.Security.SslStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00000] in <00000000000000000000000000000000>:0
    8. at BestHTTP.Extensions.WriteOnlyBufferedStream.Flush () [0x00000] in <00000000000000000000000000000000>:0 at BestHTTP.HTTPRequest.SendOutTo (System.IO.Stream stream) [0x00000] in <00000000000000000000000000000000>:0
    9. at BestHTTP.HTTPConnection.ThreadFunc () [0x00000] in <00000000000000000000000000000000>:0
    10.  at System.Threading.Tasks.Task.Execute () [0x00000] in <00000000000000000000000000000000>:0
    11.  at System.Threading.ExecutionContext.RunInt...too long be cutted!
    12.  
    and
    Code (CSharp):
    1. [BestHTTP.Connections.HTTP1Handler] Remote server closed the connection before sending response header!
    2. Previous request state: Processing. Connection state: Processing ***Exception: [BestHTTP.Connections.HTTP1Handler] Remote server closed the connection before sending response header! Previous request state: Processing. Connection state: Processing StackTrace:
    and
    Code (CSharp):
    1. SocketException
    2.  
    3. mono-io-layer-error (113) ***Exception: mono-io-layer-error (113)
    4.  StackTrace: at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00000] in <00000000000000000000000000000000>:0
    5.  at BestHTTP.PlatformSupport.TcpClient.General.TcpClient.Connect (System.Net.IPEndPoint remoteEP) [0x00000] in <00000000000000000000000000000000>:0
    6.  at BestHTTP.PlatformSupport.TcpClient.General.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, System.Int32 port) [0x00000] in <00000000000000000000000000000000>:0
    7.  at BestHTTP.HTTPConnection.Connect () [0x00000] in <00000000000000000000000000000000>:0
    8. at BestHTTP.HTTPConnection.ThreadFunc () [0x00000] in <00000000000000000000000000000000>:0
    9. at System.Threading.Tasks.Task.Execute () [0x00000] in <00000000000000000000000000000000>:0
    10. at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <0000...too long be cutted!
    We really don’t know why,Does it matter if we add these macros during the build apk:
    -define:BESTHTTP_DISABLE_COOKIES
    -define:BESTHTTP_DISABLE_CACHING
    -define:BESTHTTP_DISABLE_SERVERSENT_EVENTS
    -define:BESTHTTP_DISABLE_WEBSOCKET
    -define:BESTHTTP_DISABLE_SIGNALR
    -define:BESTHTTP_DISABLE_SOCKETIO
    -define:BESTHTTP_DISABLE_ALTERNATE_SSL
    -define:BESTHTTP_DISABLE_UNITY_FORM
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,497
    @leaverforyou

    All of these are symptoms of bad network conditions.
     
unityunity