Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Best HTTP Released

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

  1. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @karlsevenvii

    1.10.x covers a lot of versions and 1.10.0 is more than a year old by now. In this time frame WebSockets got a lot of improvements and bugfixes.
    The ReleaseNotes.txt in the \Best HTTP (Pro)\ folder can show your current version.

    Websocket shouldn't drop messages or delay them, something (like a repro-project) that helps finding out what happens would be helpful.
     
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @spiderpoison

    Most probably the server closed the connection, but it still has pending data from the server. When it tries to read those pending data on the closed socket that's the point when i think it will receive this error.

    What server are you using?
     
  3. AmirLevi

    AmirLevi

    Joined:
    Dec 5, 2012
    Posts:
    12
    Hello,
    First thing I Just want to say great job, really good asset, help me to solve a lot of problems.

    Second, I Have a problem:
    I'm downloading An assetbundle from a server, and I'm using your example of downloading large files by a stream
    and its work great doing so, but the issue is that the file I'm downloading is really a JSON file that I'm getting from the server when I post to it. This JSON file contains the assetbundle that I need.
    So my question is that, how do I stream the JSON file from byte[30](example) to byte[100](example) without reading it?

    Thanks
     
  4. grogshotgames

    grogshotgames

    Joined:
    Aug 6, 2015
    Posts:
    76
    Hello,

    I'm having a problem in a specific part of my game when connecting to a PHP.
    This happens both in iOS and Android, but it seems to be more frequent (3x times) on iOS.
    It's hard to determine what's causing it, because this error does not always happen, and I haven't been able to reproduce it.

    Supposedly, it's thrownig a ConnectionTimeout error, which is set to 20 seconds. This means it's not even able to connect to the php and it isn't any problem related with the php code itself, right? The weird thing, as I said.. is that this is not happening every time, so it's hard to assess why it's happening.

    I'm sorry for providing so little information, but there's nothing much I can do, actually.

    Does it ring any bell?
     
  5. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @tiptip

    I'm not sure about your goal or if i'm understand well what you wrote. If your data is in JSON, in the end you have to create a large text from the downloaded data to be able to parse it.
     
  6. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @grogshotgames

    If the error is ConnectionTimeout, then it can't be your php code's fault (no request reached any php code).

    Without more information I can just guess here, but under poor network conditions 20 sec to connect can be too low. You can try to increase it to 40 of 60 secs to see whether you see less errors.
     
  7. Christian_G

    Christian_G

    Joined:
    Aug 22, 2017
    Posts:
    3
    Hey, i get problems if i build my project for UWP. I get no connection and get the following message in the debug log:

    -WebSocket closed! Code: 1005 Message:
    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug.bindings.h Line: 43)


    any idea about the problem? If i build the project for android everything works fine. Best regards
     
  8. grogshotgames

    grogshotgames

    Joined:
    Aug 6, 2015
    Posts:
    76
    Yeah, as I said, I'm sorry for not being able to provide more info, but it's been really hard for us to debug and obtain info on this. It's happened to us under a good connection, so it's weird... and it's not easily replicable. Maybe it could be an issue with our servers directly?

    At first, I thought this was caused due to an article I found saying iOS accepts 4 concurrent connections to the same host, but you already said this could not be the case, and we, just in case tried to connect via a different subdomain... to no avail.

    40 seconds, as you suggest, seem a lot, to be honest. I'll try to increase it to see if anything changes, though.
     
  9. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @Christian_G

    Can you share more details about your build environment (plugin and unity version, relevant player settings like scripting runtime version, backend)?
    Is this reproducable with my sample? Are you using the WebSocket protocol, or a higher one that depends on it?
     
  10. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @grogshotgames

    The plugin uses the very same code for Android and iOS, so I don't know what can cause timeouts on iOS if not network conditions.
    What can make a different is to set ConnectTimeout to zero, it will use non-asynchronous connect and dns querying. I heard in one case that it solved connect problems (it might have been different problem than yours though).
     
  11. jgeibel

    jgeibel

    Joined:
    May 5, 2016
    Posts:
    7
    One of my former co-workers purchased and added this plugin to our Unity project. In the process of looking into upgrading our version of Unity from 5.6.5 to 2018.1.8 and I'm seeing a number of warnings that I suspect might be fixed in a current version. Unfortunately, he didn't check into git the ReleaseNotes.txt (or any file with "release" or that is a .txt). Can someone assist with helping us get an updated version?
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @jgeibel

    Logging in with the account that it has been purchased, you should be able to update the package to the latest one.
     
  13. jgeibel

    jgeibel

    Joined:
    May 5, 2016
    Posts:
    7
    Thanks. Unfortunately, that Unity account was deleted when he left.
     
  14. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    54
    Hi,

    Is there a way to read responses of multiple types, for example a binary file + a json containing some metadata about the file? From what I can see I can either use response.Data or response.DataAsText.
    Thanks!
     
  15. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @Numa

    You should use Data as it contains the raw bytes. And of course you can send down more than one type of content, but you will have to know where one starts and ends (some kind of metadata you already mentioned).
     
  16. Notsu

    Notsu

    Joined:
    May 5, 2015
    Posts:
    7
    Hi,

    I'm doing a proof of concept connexion with socket.io in one hand, and unity ( besthttp ) on the other hand. I'm getting troubles to keep the connexion alive : it connect properly, but after some seconds ( 5-6 ) , it disconnects and reconnect just after, server side I have this explanation in logs : client namespace disconnect
    I tried to explicitly configure a namespace, with success, but the problem persists. Do you have an clue about what's wrong ?
    With another lib ( unity socket.io ) I don't have this issue but I want to continue with your implementation.
    Thanks !
     
  17. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @Notsu

    What version of the plugin are you using? There were an issue with ping timeout handling, but i fixed that in v1.10.4.
     
  18. Notsu

    Notsu

    Joined:
    May 5, 2015
    Posts:
    7
    I see that the ping timeout is 5000 :

    engine:ws writing "0{"sid":"c0r-serRcNLwm7epAAAB","upgrades":[],"pingInterval"
    :25000,"pingTimeout":5000}"

    So I wonder : do I have to implement the ping/pong dance, or is it already managed by besthttp implematation ( wich seams to me a part of the rfc )
    Thanks.
     
  19. Notsu

    Notsu

    Joined:
    May 5, 2015
    Posts:
    7
    Ho great I'm in 1.9.17, I'll upgrade ^^
     
  20. Notsu

    Notsu

    Joined:
    May 5, 2015
    Posts:
    7
    It was an issue of version, thx a lot :)
     
  21. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @Notsu Great, I'm happy I could help!
     
  22. berry4u

    berry4u

    Joined:
    Dec 27, 2017
    Posts:
    18
    Hi
    Trying to run the SampleSelector. Running the Connection API example I have the following error:
    [636681503603690059] Err [SignalR Connection]: Negotiation request finished Successfully, but the server sent an error. Status Code: 403-Site Disabled Message:

    This occurs with the last version and with the previous too.

    Regards
    Berardo
     
  23. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
  24. berry4u

    berry4u

    Joined:
    Dec 27, 2017
    Posts:
    18
  25. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    362
    Hi All
    I am interested in using UnityWebRequest to make REST requests to the Watson Machine Learning( this service is not included in the Watson SDK for Unity at the moment)
    Since that Watson SDK for Unity does not support PUT operations( by RESTConnector class), I would need to create a new Class that use UnityWebRequest( this one support PUT operations) to make REST requests to the Watson Machine Learning service, for it and sorry for my ignorance but Could I use the Best HTTP plugin to do it?
    Thanks for your time
    Alejandro Castan
     
  26. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @castana1962

    Yes, you can use the plugin to do PUT requests:
    Code (CSharp):
    1. var request = new HTTPRequest(new Uri("http://httpbin.org/put"), HTTPMethods.Put, (req, resp) => {
    2.     // TODO: handle response
    3. });
    4.  
    5. // add form-fields to the request
    6. request.AddBinaryData("file", tex.EncodeToPNG(), "image.png", "image/png");
    7. request.AddField("json", "{name\":\"name of image\",\"filename\":\"image.png\"}");
    8.  
    9. request.Send();
    Let me know if you have any questions!
     
    castana1962 likes this.
  27. Onutrem

    Onutrem

    Joined:
    Dec 8, 2017
    Posts:
    3
    Hello.

    I have an issue with my antirus (avast) is flagging my game with Best HTTP as an IDP Generic virus.
    It doesn't happen when I scan the .exe freshly created. But after few minutes of use, the exe is flagged as a virus by Avast.

    I wanted to know if someone using had this issue. Or if it's on unity side.
     
  28. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @Onutrem

    I think you should write to Unity. The plugin uses APIs available for every Unity application and the lowest level one is the Socket class.
     
  29. dshewmaker

    dshewmaker

    Joined:
    Oct 31, 2013
    Posts:
    17
    Doc is wrong on this line on page 11. ints changed to longs at some point and documentation is old type:
    void OnDownloadProgress(HTTPRequest request, int downloaded, int length)

    function is now:

    void OnDownloadProgress(HTTPRequest request, long downloaded, long length)
     
  30. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @dshewmaker

    That's interesting as I changed those ints to longs months ago and in my version they are there properly:
    upload_2018-8-17_8-4-59.png
     
  31. dshewmaker

    dshewmaker

    Joined:
    Oct 31, 2013
    Posts:
    17

    ok, good, perhaps it did not get updated on mine for some reason... Just letting others know. Thanks for updating BestHTTP.
     
  32. mark-shin

    mark-shin

    Joined:
    Apr 20, 2014
    Posts:
    1
    We got this problem.
    Some https connection (not all https) is failed with this message.

    There is no lb on that server.
    And below code does not work.
    "HTTPManager.UseAlternateSSLDefaultValue = false;"
    it also fail with "The authentication or decryption has failed." message

    However connection to "https://eosknights.io/config/config-mainnet.json" works fine
     
  33. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @mark-shin

    There are certificates/algorithms that the default SSL handler can't handle. The plugin as you may already know comes with two SSL handler. The default one is the BouncyCastle, and the other one is the .net SslStream.
    SslStream was the less advanced so i made the BouncyCastle one the default, but in recent Unity versions SslStream became quite good. With Unity 2018.2 you can set UseAlternateSSLDefaultValue to false and able to connect to https://rpc.eosys.io successfully.
     
  34. Genom

    Genom

    Joined:
    Dec 2, 2014
    Posts:
    71
    Hi Guys! not exactly a BestHttp issue, but somehow related (I'm using the preview signalr core client) and maybe you´ve found how to configure properly a reverse proxy from a dmz server (IIS and url rewrite) to the internal one running the asp.net core that contains the hub.

    Here you are the Stackoverflow

    If you know how to do it I would really appreciate it if you can share it, and maybe it helps other ones.

    Btw, I tested with both besthttp and javascript client, and signalr 2.2.1 and core, and it happens the same so it is not a bug in your wonderful pluging.

    cheers!
     
  35. TriPawCat

    TriPawCat

    Joined:
    Nov 23, 2015
    Posts:
    7
    Hi, I finally resolve the problem. BestHTTP handle timeout with the method socket.Close(); and I change it into socket.Disconnect(true), or socket.Disconnect(false), both work. It won't block other socket, I guess when call socket.Close(); it doesn't close immediately.
     
  36. GFernandes

    GFernandes

    Joined:
    Dec 5, 2013
    Posts:
    2
    I haven't bought BestHTTP yet, but before I do I need to know if the socket.io implementation supports receiving data in different forms for the sake of backwards compatibility. I have a current server emitting events with parameters of different types (object, string, int, etc), and a client in html5 already working with this protocol. Will it work with the BestHTTP socket.io client implementation?
     
  37. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @TriPawCat

    Can you help me by describing where you changed exactly Close to Disconnect?
     
  38. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @GFernandes

    With a server code like this:
    Code (JavaScript):
    1. io.on('connection', function (socket) {
    2.     var object = {
    3.         'strProperty': 'str value',
    4.         'intProperty': 123
    5.     };
    6.  
    7.     socket.emit("types-test", object, 321, "str param");
    8. });
    You can write the client code with the plugin like this:
    Code (CSharp):
    1. var manager = new SocketManager(new Uri("http://localhost:3000/socket.io/"));
    2. manager.Socket.On("types-test", OnTypesTest);
    3.  
    4. private void OnTypesTest(Socket socket, Packet packet, object[] args)
    5. {
    6.     // expected arguments: args[0]: object, args[1]: 321, args[2]: "str param"
    7.  
    8.     Dictionary<string, object> objDict = args[0] as Dictionary<string, object>;
    9.     var obj = new
    10.     {
    11.         strProperty = objDict["strProperty"].ToString(),
    12.         intProperty = (int)(double)objDict["intProperty"]
    13.     };
    14.     int num = (int)(double)args[1];
    15.     string str = args[2].ToString();
    16.  
    17.     Debug.Log("Object - strProperty: " + obj.strProperty + " intProperty: " + obj.intProperty);
    18.     Debug.Log("num: " + num);
    19.     Debug.Log("str: " + str);
    20. }
    Producing a log like this:
    upload_2018-8-23_18-17-9.png
     
  39. GFernandes

    GFernandes

    Joined:
    Dec 5, 2013
    Posts:
    2
    Cool, perfect!
     
  40. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    54
    Hi,
    I'm downloading a gallery of about 1000 images (~50kb each) in a loop (1000 individual requests). Instead of getting the images back one by one I get nothing for about 30 seconds then everything comes down at once. What's the correct way to do it? Is the server choking (don't think so as it is behind a caching layer) or is there too much overhead in unity creating 1000 requests at once? Thanks!
     
    Last edited: Aug 26, 2018
  41. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @Numa

    By default the plugin will not send out all of the 1000 requests (if the pictures are on the same server) only the first 4.
    Non-sent requests will be in a queue and one finishes it will send out the next from the queue.

    I tried it out and while it downloaded the same 9 images over and over without caching, it worked as expected.

    If it's possible to send a repro project to me in private (in mail or through a private message on this forum) i can take a look on it.
     
  42. TriPawCat

    TriPawCat

    Joined:
    Nov 23, 2015
    Posts:
    7
    It's in the TcpClient.cs, line 347.

    36062381-39B1-46CC-AD27-CA2E5AA591ED.png
     
  43. spiderpoison

    spiderpoison

    Joined:
    Jul 2, 2018
    Posts:
    8
    I use websocket of this plugin, communicate with server with gorilla websocket of golang(https://github.com/gorilla/websocket).
    Sometimes the gorilla websocket found the message was bad with error "unexpected reserved bits 0x40"
    Below pictures is from the gorilla websocket .
    upload_2018-8-28_7-15-51.png

    upload_2018-8-28_7-15-23.png
    First I suspected this is because the server had any RACE of ReadMessage.
    And compiled the server with -race, but with the error happened without ant RACE.
    So I suspected the client send bad data to server, or i had the wrong way to using the plugin, or the plugin need some config to match gorilla websocket?
    Please give me some advice, thanks.
     
  44. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @spiderpoison

    rsv1Bit is set only when the compression extension is negotiated and the frame contains compressed data. (https://tools.ietf.org/html/rfc7692#section-7.2.3.1)
    Code (CSharp):
    1.     c.readDecompress = false
    2.     if c.newDecompressionReader != nil && (p[0]&rsv1Bit) != 0 {
    3.         c.readDecompress = true
    4.         p[0] &^= rsv1Bit
    5.     }
    6.  
    7.     if rsv := p[0] & (rsv1Bit | rsv2Bit | rsv3Bit); rsv != 0 {
    8.         return noFrame, c.handleProtocolError("unexpected reserved bits 0x" + strconv.FormatInt(int64(rsv), 16))
    9.     }
    It might be possible that gorilla accepted the negotiation but newDecompressionReader still nil? In that case it throws an error instead of handling of the compressed data.

    You can also disable the extension on client side by passing null as the last parameter to the websocket constructor:
    Code (CSharp):
    1. new WebSocket(/*uri: */ new Uri(address), /*origin: */ null, /*protocol: */ null, /*extensions: */ null);
     
  45. spiderpoison

    spiderpoison

    Joined:
    Jul 2, 2018
    Posts:
    8
    @BestHTTP
    Thanks for your reply.
    So dose it mean I receive the date form client need to decompress?
    Should I set newDecompressionReader not nil?

    That means I should set EnableCompression of Upgrader to true.
    ```
    // EnableCompression specify if the server should attempt to negotiate per
    // message compression (RFC 7692). Setting this value to true does not
    // guarantee that compression will be supported. Currently only "no context
    // takeover" modes are supported.
    EnableCompression bool
    ```

    Another question, when will the plugin send compressed data? I want to test the modification of server
     
    Last edited: Aug 28, 2018
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @spiderpoison

    Yes, the server should decompress the received data, but because the newDecompressionReader probably nil, it throws an error instead.
    I don't think you should set newDecompressionReader manually. Wrote a reply to your github issue.
    By default the plugin will compress data if its length is >= 5 bytes.
     
  47. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    54
    @BestHTTP Thanks I'll send you a test project soon.
     
  48. spiderpoison

    spiderpoison

    Joined:
    Jul 2, 2018
    Posts:
    8
    @BestHTTP
    If the data length is >= 5 bytes. It will be send compressed?
    Our message almost all > 5 bytes.
    But the rate of error "unexpected reserved bits 0x40" is about 6%.

    And
    Code (CSharp):
    1. new WebSocket(/*uri: */ new Uri(address), /*origin: */ null, /*protocol: */ null, /*extensions: */ null);
    Now we don't pass param "extensions"
    I use like this:
    Code (CSharp):
    1. new WebSocket( new Uri( address ), "/ws", null );
    And the definition like this:
    Code (CSharp):
    1.         public WebSocket(Uri uri, string origin, string protocol
    2. #if !UNITY_WEBGL || UNITY_EDITOR
    3.             , params IExtension[] extensions
    4. #endif
    5.             )
    the extensions is params, and now i don't pass it. So should i pass nil to extensions?

    if i set param extensions null, will forbid compressing?
    Or
    How do I pass server request header about Sec-WebSocket-Extensions?
    Or
    How do I pass server response header to forbid extensions?
     
    Last edited: Aug 29, 2018
  49. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,368
    @spiderpoison

    If you use new WebSocket( new Uri( address ), "/ws", null ) than you don't have to. Is the server error still present when you use this constructor?

    Yes, if you specify null for the extensions than it will not try to use compression.

    You shouldn't do either of these. These are the extensions' and plugin responsibility.
     
  50. spiderpoison

    spiderpoison

    Joined:
    Jul 2, 2018
    Posts:
    8
    @BestHTTP
    yes, server error when i use WebSocket( new Uri( address ), "/ws", null )
    The error don't happen everytime, about 6% rate.

    Is there any possible, pulgin will compress data without extensions?
    I notice reconnect will call
    Code (CSharp):
    1.         public WebSocket(Uri uri)
    2.             :this(uri, string.Empty, string.Empty)
    3.         {
    4. #if (!UNITY_WEBGL || UNITY_EDITOR) && !BESTHTTP_DISABLE_GZIP
    5.             this.Extensions = new IExtension[] { new PerMessageCompression(/*compression level: */           Decompression.Zlib.CompressionLevel.Default,
    6.                                                                            /*clientNoContextTakeover: */     false,
    7.                                                                            /*serverNoContextTakeover: */     false,
    8.                                                                            /*clientMaxWindowBits: */         Decompression.Zlib.ZlibConstants.WindowBitsMax,
    9.                                                                            /*desiredServerMaxWindowBits: */  Decompression.Zlib.ZlibConstants.WindowBitsMax,
    10.                                                                            /*minDatalengthToCompress: */     5) };
    11. #endif
    12.         }
    I don't understand very well when will call reconnect.
    Is there any way can close Extensions?
     
    Last edited: Aug 29, 2018