Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Best HTTP Released

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

  1. hermit_021

    hermit_021

    Joined:
    May 31, 2018
    Posts:
    6
    @BestHTTP Hi, I'm using best http 2 for my game. There is strange issue in receiving broadcast.
    There are 2 players on the table when 2nd player joins the table for the first time he doesn't get any broadcast he has to rejoin the table but 1st player gets all broadcast he doesn't have to rejoin.
     
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @hermit_021

    It would be very valuable to know what protocol are you using (socket.io, signalr, etc.), and how do you send your broadcasts.
     
  3. hermit_021

    hermit_021

    Joined:
    May 31, 2018
    Posts:
    6

    @BestHTTP, I'm using socket.io. and let me describe it bit more. as I said second player is not getting broadcast but the case is, there are two classes for both i have subscribe the broadcast in onenable one of them is called but not the other one. Both are active in scene in debug i get logs for onenable method from both classes from both players but both methods of that broadcast is called for 1st joined player only 2nd player have to rejoin in order to get call both methods.
     
  4. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
  5. hermit_021

    hermit_021

    Joined:
    May 31, 2018
    Posts:
    6
    upload_2022-10-13_16-13-4.png

    upload_2022-10-13_16-13-25.png

    Both game objects are active and both scripts are also enabled.
     
  6. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @hermit_021 I couldn't replicate your issue, and in this case verbose logging wouldn't help as On and Off cals aren't logged. So could you send a minimal repro project?

    Also, please note that calling Off removes all callbacks for that event name!
     
  7. gawoon

    gawoon

    Joined:
    Dec 11, 2017
    Posts:
    7
    @BestHTTP
    hi, here's my context.
    i'm using socketio3 to send my webcamtexture to python server.
    i have a texture which has a resolution about 640x480, and i encoded it to JPG format, and then send it through socketio.
    i profiled with my tablet Lenovo P11, and i'd like to know how to optimize this.
    it seems that zlib take a lot of time.
    is there way not to compress my data before sending?
    any other solution will save me
    thanks in advance.
    upload_2022-11-3_2-19-8.png
     

    Attached Files:

  8. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @gawoon The new version in the works can help solving it by
    1. giving a way to disable websocket extensions
    2. moving extension and websocket frame creation to the sender thread

    In your case both will be helpful as JPG already a compressed format, further compression can be only a waste of CPU time, so disabling the per-message deflate extension is a good step to consume less cpu.

    If you drop me a mail at besthttp@gmail.com i can send a package with the new version.
     
    choigw likes this.
  9. choigw

    choigw

    Joined:
    Jul 21, 2020
    Posts:
    2
    awesome!
    here's my email, choigawoon@gmail.com
    also wonder if when do you think new version is released on the package manager?
    oops, i sent the mail to you also.
     
  10. gawoon

    gawoon

    Joined:
    Dec 11, 2017
    Posts:
    7
    hi again.
    your solution work perfectly. thanks a lot!
    before about 100ms -> now about 1-2ms upload_2022-11-4_8-6-41.png
     
    BestHTTP likes this.
  11. 1002711414

    1002711414

    Joined:
    Dec 16, 2021
    Posts:
    1
    Hello,How to Authentication by password and username?
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
  13. JosephEgens

    JosephEgens

    Joined:
    May 5, 2020
    Posts:
    3
    @BestHTTP
    Hello,
    I have been experiencing a problem with the BestHTTP package for some time, on some Android devices the HTTPRequest functions and requests with SignalR (HubConnection when sending) crash the application. I did several tests but the application crashes without any particular message on the Play Store (except a SIGBUS and SIGSEGV message and more recently a "[libil2cpp.so] BestHTTP47.cpp - FastChaCha7539Engine_DoFinal_mB94251F11244EE9C50414238F8C1CF04D467191A" message related to a SIGBUS error). I changed the HTTPRequest functions to UnityWebRequest and it works but I haven't found an alternative for SignalR.

    (I would like to point out that this crash only happens to 1% of our users and they all use a Samsung Galaxy A13)

    Thanks in advance for your help!

    Edit : I'm using Unity 2021.3.16f1
     
  14. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @JosephEgens What version of the plugin and Unity are you using?
     
  15. JosephEgens

    JosephEgens

    Joined:
    May 5, 2020
    Posts:
    3
    I'm using Unity 2021.3.16f1 and BestHTTP/2 V 2.8.2
     
  16. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @JosephEgens I saw nothing suspicious in the FastChaCha7539Engine's DoFinal method, however under Unity 2021.2 or newer it uses BouncyCastle's new Span based APIs.
    Drop me a mail at besthttp@gmail.com (or you can join to the plugin's discord server and send a private message) and will send a new package that will disable the Span based APIs so we can see whether it makes any change.
     
  17. JosephEgens

    JosephEgens

    Joined:
    May 5, 2020
    Posts:
    3
    Hello,
    Thank you for your reactivity, with the plugin that you sent me, the requests do not cause any more crashes and work properly.
    Thank you again for your help !
     
    BestHTTP likes this.
  18. darydol

    darydol

    Joined:
    May 19, 2017
    Posts:
    9
    I made it as an echo server with WebsocketSharp, and made it as a BestHTTP.WebSocket client and tested it, but the following error occurred.
    This is for a simple test to send and receive 38,553 bytes. please tell me how to solve it
    Request Finished with Error! Exception: TCP Stream closed unexpectedly by the remote server
    at BestHTTP.WebSocket.Frames.WebSocketFrameReader.ReadByte (System.IO.Stream stream) [0x00010] in G:\T01\Assets\Best HTTP\Source\WebSocket\Frames\WebSocketFrameReader.cs:181
    at BestHTTP.WebSocket.Frames.WebSocketFrameReader.Read (System.IO.Stream stream) [0x00001] in G:\T01\Assets\Best HTTP\Source\WebSocket\Frames\WebSocketFrameReader.cs:60
    at BestHTTP.WebSocket.WebSocketResponse.ReceiveThreadFunc () [0x00011] in G:\T01\Assets\Best HTTP\Source\WebSocket\WebSocketResponse.cs:402
     
  19. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @darydol What version of the plugin are you using? You can check it by printing out HTTPManager.UserAgent (or just check it in the source).
     
  20. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    149
    Hi @BestHTTP !
    We have a question regarding your TLS plugin.
    Can't we get any problem with security if anybody on Android can access the folder where you store the metadata? Any sensitive data there?
     

    Attached Files:

  21. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
  22. unity_ci

    unity_ci

    Joined:
    Oct 31, 2019
    Posts:
    1
    Hi @BestHTTP.
    When I try to make an HTTP/2 GET request on the device with the Turkish language as a default, it is declined by the server. The client error is
    Code (CSharp):
    1. Exception: System.Exception: RST_STREAM frame received! Error code: PROTOCOL_ERROR(1)
    The server error is invalid_headers.

    The headers from Charles are provided in the image below, and two of the headers have strange symbols instead of the letter "I". I do not modify these 2 headers anywhere in my app, but I see that they are used in the BestHttp plugin. Do you know how I can fix this?
     

    Attached Files:

    Last edited: Mar 27, 2023
  23. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @unity_ci
    Thanks for the details! The plugin used ToLower instead of ToLowerInvariant in a few places. Sent a link to an updated package in private.
     
    unity_ci likes this.
  24. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    288
    Hey BestHTTP team, we're devloping an AR app that initially loads textures over HTTP to put them on objects around you. We implemented a job system that schedules the texture downloads based on how close those objects are to the user, so not all of them are being loaded at once.

    We were still seeing frame drops when using Unity's texture download, so we switched to BestHTTP's download implemention hoping that we can get rid of these frame drops as it is multi-threaded.

    However, we noticed that the frame drops still occur. When profiling, we saw that in each performance spike around 95% of the time is spent on the HTTPUpdateDelegator. Below that node, we see a lot of GC.Alloc calls for around 62mb of data. Is there any chance to speed up things here?

    EDIT: The problem was caused by another library which I called in the callback. So all good, sorry for bothering.
     
    Last edited: Apr 3, 2023
  25. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @waldgeist

    HTTPUpdateDelegator is the link between the plugin and Unity. Its Update function is called by Unity, and that's where all the callbacks are called. Because of this, everyhing you do in the HTTPRequest's callback will be show up under HTTPUpdateDelegator in the profiler.
    Also, all memory for the downloaded content is allocated outside of the Unity main thread, if you access the content through HTTPResponse's Data property, the plugin doesn't allocate any additonal memory. If you use DataAsTexture2D, then the plugin only creates the Texture2D:
    Code (CSharp):
    1. public Texture2D DataAsTexture2D
    2. {
    3.     get
    4.     {
    5.         if (Data == null)
    6.             return null;
    7.  
    8.         if (texture != null)
    9.             return texture;
    10.  
    11.         texture = new Texture2D(0, 0, TextureFormat.RGBA32, false);
    12.         texture.LoadImage(Data, true);
    13.  
    14.         return texture;
    15.     }
    16. }
    The plugin also has an internal BufferPool to reuse allocated byte[]s, and there's a very high chance that after the first download the plugin only allocates memory for the final downloaded content (except the headers of course).
     
  26. Ludogram

    Ludogram

    Joined:
    May 17, 2019
    Posts:
    2
    Hello, sorry to bother but it seems I'm having some issue with BestHTTP when my Managed Stripping Level is set to minimal. When it's on disabled everything is working fine but when it's on minimum I'm getting this error :

    Unfortunately since we are releasing our project on IL2CPP plateform we can't disable Managed Stripping Level.
    I've tried putting BestHTTP and other things in a link.xml file to prevent them for being stripped but it didn't work.

    Code (csharp):
    1. <linker>
    2.   <assembly fullname="System">
    3.     <type fullname="System" preserve="all" />
    4.   </assembly>
    5.   <assembly fullname="UnityEngine">
    6.     <type fullname="UnityEngine" preserve="all" />
    7.   </assembly>
    8.   <assembly fullname="BestHTTP">
    9.     <type fullname="BestHTTP" preserve="all" />
    10.   </assembly>
    11. </linker>
    It might come from a different script being stripped but at this point I'm stuck and only see this.
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @Ludogram

    The exception happened in MMatchmaking.Match (DirectoryGame game, System.Boolean host) [0x0002d] in C:\\[path]\\MMatchmaking.Command.cs:22 \r\n at MMatchmaking.<_NewOnlineGame>b__55_0 (BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse res) [0x00034] in C:\\[path]\\MMatchmaking.Directory.cs:128.

    You might have to add a few of your own classes too (like DirectoryGame, _NewOnlineGame, etc.) to preserve by managed stripping.
     
  28. Ludogram

    Ludogram

    Joined:
    May 17, 2019
    Posts:
    2
    @BestHTTP thanks for the quick answer.

    Unfortunately, I used the attribute [UnityEngine.Scripting.Preserve] in several script and I'm getting the same error.
    I used it in : RequestEvents, HTTPUpdateDelegator, HTTPManager and two personnal script that are in the error, MMatchmaking.Directory and MMatchmaking.Command (which include MMatchmaking.Match)
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @Ludogram The plugin doesn't require any more Preserve attributes, it already have it where would problems.

    The exception happens in a HTTPRequest callback where most probably you try to parse the downloaded content (json). I don't know what's your classes look like, so i can't help too much, but you might have to add Preserve to fields/properties too. Or alternately, add the assembly+namespace to the link.xml.
     
  30. vuthang

    vuthang

    Joined:
    Mar 7, 2017
    Posts:
    29
    Hi, How I can set websocket No Delay? I see webSocket.InternalRequest.TryToMinimizeTCPLatency is removed
     
  31. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    @vuthang The plugin sets NoDelay for all TCP connection. WebSocket frames are sent out as soon as possible.
     
    vuthang likes this.
  32. hermit_021

    hermit_021

    Joined:
    May 31, 2018
    Posts:
    6
    @BestHTTP


    Socket connection issue in carrier network
    we are using this plugin for multiplayer game and from last 3 days we found socket connection issue in Reliance JIO carrier in India
    i am doing socket connection but socket is not connected to that server for JIO carrier rest carrier it works fine
    so can you please help out for same to resolve
    as we have try to connect with socket io version 2 and version 3 both
    but not works

    awaiting for response

    Thanks
     
  33. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640
    hermit_021 likes this.
  34. virtouso

    virtouso

    Joined:
    Jul 12, 2013
    Posts:
    54
    is it possible to have a signalr server in unity? i need to make my clients directly connect to server that can run unity features.
     
  35. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,640