Search Unity

Best HTTP Released

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

  1. dev_runeofdark

    dev_runeofdark

    Joined:
    Oct 27, 2016
    Posts:
    10
    @BestHTTP

    I am using the stable scripting backend not the experimental. and here are the logs what i got from the log function you mentioned.
    unity_logs.PNG
    I know now how I can fix it, in the log I saw that besthttp automatically put a port number at the end of the url 80 for http and 443 for https. This is the problem because the router of heroku assigns the port automatically.

    My question is now is there an option that prevents besthttp to put a port at the end of the url?
     
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @dev_runeofdark

    I don't know Heroku, but the plugin must know a port number to connect to.
    Port number 80 and 443 are the default HTTP and HTTPS ports, so if you don't specify one, the plugin will assume the defaults. (The host name identifies a machine on the internet, and the port number identifies the service on that machine. Port numbers needed because one machine can host more than one service, so they are indicate what service connect to.)
     
  3. Agrum

    Agrum

    Joined:
    Jan 7, 2018
    Posts:
    2
    @BestHTTP

    Hello, is there a way to load my previous cookie jar when re-launching the app ? My server gives me a session id cookie after login and I'd like it to be persistent until it expires. Is it suppoerted by BestHTTP or should I managed this myself ?

    Edit:
    • RootCacheFolderProvider: By default the plugin will save all cache and cookie data under the path returned by Application.persistentDataPath. You can assign a function to this delegate to return a custom root path to define a new path. This delegate will be called on a non Unity thread!
    I found the Cookies folder with a Library file in it. It seems to be encoded. How do I make sure that the cookies are loaded when the app is launched ? My server tells me the requests before login do not have cookies.

    Edit:
    BestHTTP.Statistics.GeneralStatistics tells me I have 0 cookies when starting, then one when my server returns my session id.

    Thanks.
     
    Last edited: Mar 23, 2018
  4. fafase

    fafase

    Joined:
    Jul 3, 2012
    Posts:
    156
    OK my bad, makes sense.
     
  5. dev_runeofdark

    dev_runeofdark

    Joined:
    Oct 27, 2016
    Posts:
    10
    @BestHTTP

    I had this problem before with another plugin. After a search of a few hours. I found out that you only need the URL and that heroku search automatically for the right port the server is listening.

    But if it is not posible to make a option to prevent to put the default port at the end. May you know how to switch from HTTP v 1.1 to HTTP v 1.0
     
  6. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @Agrum

    The plugin will save all non-session cookies, and will delete all expired cookies on load. If the server send no Max-Age or Expires attribute for the cookie, then it's considered as a session cookie.

    It would be helpful to know what exactly the Set-Cookie header of the response looks like.
    You use an intermediate proxy (like Charles) to capture requests and response. You can set up the plugin to use the proxy like this:
    Code (CSharp):
    1. BestHTTP.HTTPManager.Proxy = new BestHTTP.HTTPProxy(new Uri("http://localhost:8888"), null, true);
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @dev_runeofdark

    While the plugin connects to the default ports and displays it in the logs, it will not send the port number in its headers. Heroku should be able to route the request properly.

    While changing the request line from HTTP/1.1 to HTTP/1.0 in the HTTPRequest.cs would inform the server that it's a 1.0 request, there are more conditions that should be met for a lower version of the protocol. So, it might work but there's no guarantee.
     
  8. Agrum

    Agrum

    Joined:
    Jan 7, 2018
    Posts:
    2
    "Expires" field was not set from server. Thanks for helping out, working fine now.
     
  9. pachash

    pachash

    Joined:
    Apr 2, 2014
    Posts:
    55
    @BestHTTP

    I'm using BaseHTTP Pro 1.9.16 and I've got some crash reports from players with the following stack trace:

    Code (csharp):
    1. SocketException: Connection timed out
    2. System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags)
    3. System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size)
    4. Org.BouncyCastle.Crypto.Tls.RecordStream.WriteRecord (Byte type, System.Byte[] plaintext, Int32 plaintextOffset, Int32 plaintextLength)
    5. Org.BouncyCastle.Crypto.Tls.TlsProtocol.SafeWriteRecord (Byte type, System.Byte[] buf, Int32 offset, Int32 len)
    6. Org.BouncyCastle.Crypto.Tls.TlsProtocol.RaiseAlert (Byte alertLevel, Byte alertDescription, System.String message, System.Exception cause)
    7. Org.BouncyCastle.Crypto.Tls.TlsProtocol.FailWithError (Byte alertLevel, Byte alertDescription, System.String message, System.Exception cause)
    8. Org.BouncyCastle.Crypto.Tls.TlsProtocol.HandleClose (Boolean user_canceled)
    9. Org.BouncyCastle.Crypto.Tls.TlsStream.Close ()
    10. BestHTTP.HTTPConnection.Abort (HTTPConnectionStates newState)
    11. BestHTTP.HTTPManager.OnUpdate ()
    12. Rethrow as IOException: Write
    I've checked the release logs since 1.9.16 up to the latest version 1.10.3 and I've not found any entries on this issue. So I'm wondering whether it's a known bug?
     
  10. roger-yoo

    roger-yoo

    Joined:
    Oct 26, 2014
    Posts:
    7
    We have an action game that uses socket.io. (android/ios)
    Occasionally, when playing with a large number of people,
    client can not receiving messages from the server immediately.
    The response speed of the server was not a problem, and other players were able to play normally.
    The no_delay option is on.
    I do not have any clues, but what about suspicious causes?
     
  11. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @pachash

    It looks that the plugin aborted the request as it wasn't finished in the given time (HTTPRequest's Timeout). You can increase the default request timeout from 60 seconds to a higher value:
    Code (CSharp):
    1. BestHTTP.HTTPManager.RequestTimeout = TimeSpan.FromMinutes(5);
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @roger-yoo

    Is it possible that when there are a lot of players some of them will receive more and/or larger messages?
    Other than this, I see no reason how player base could affect a set of player's message processing speed.
     
  13. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @Jeremy-Lv

    Thanks for the stack trace, I think that helps a lot.
    As I see it crashes somewhere in the UnityWebRequestProto.h around line 216. My plugin although doesn't use anything like that. Are you using UnityWebrequest somewhere in your code?
     
  14. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @Jeremy-Lv

    Also, your first code snippet has some issues, although it might not related to your current problem. The response object can be null, when the plugin can't reach the server, in this case response.DataAsText will produce a NullReferenceException. You should first check the request's State, and when its Finished, response will be a valid object! Something like this:
    Code (CSharp):
    1. HTTPRequest request = new HTTPRequest(new Uri(url), (req, response) =>
    2. {
    3.     switch (req.State)
    4.     {
    5.         // The request finished without any problem.
    6.         case HTTPRequestStates.Finished:
    7.             if (response.IsSuccess)
    8.             {
    9.                 string recestr = response.DataAsText;
    10.                 byte[] receivedata = Convert.FromBase64String(recestr);
    11.                 // ...
    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.                                                 response.StatusCode,
    16.                                                 response.Message,
    17.                                                 response.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. });
     
  15. Jeremy-Lv

    Jeremy-Lv

    Joined:
    Mar 17, 2013
    Posts:
    16
    Thanks a lot ! ,I will do another research for this bug .
     
  16. koohddang

    koohddang

    Joined:
    May 14, 2013
    Posts:
    2
    I found some bugs

    DefaultLogger.cs:100

    Code (CSharp):
    1. sb.AppendFormat("{0}: {1} {2}", counter++.ToString(), ex.Message, ex.StackTrace);
    to

    Code (CSharp):
    1. sb.AppendFormat("{0}: {1} {2}", counter++.ToString(), exception.Message, exception.StackTrace);
     
    BestHTTP likes this.
  17. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
  18. helloworldgames

    helloworldgames

    Joined:
    Mar 16, 2017
    Posts:
    60
  19. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @helloworldgames

    You can already use something like this:
    Code (CSharp):
    1. HTTPRequest request = new HTTPRequest(new Uri("http://httpbin.org/get"));
    2.  
    3. yield return MEC.Timing.WaitUntilFalse(request.Send().MoveNext);
    Send() returns with the very same request.
    MoveNext() is a function of the HTTPRequest class that checks the state of the request:
    Code (CSharp):
    1. public bool MoveNext()
    2. {
    3.     return this.State < HTTPRequestStates.Finished;
    4. }
    So this is equivalent to the first one:
    Code (CSharp):
    1. HTTPRequest request = new HTTPRequest(new Uri("http://httpbin.org/get"));
    2. request.Send();
    3. yield return MEC.Timing.WaitUntilFalse(() => request.State < HTTPRequestStates.Finished);
     
    helloworldgames likes this.
  20. helloworldgames

    helloworldgames

    Joined:
    Mar 16, 2017
    Posts:
    60
    Thanks :)
     
  21. othercrow

    othercrow

    Joined:
    Oct 19, 2013
    Posts:
    15
    Hi @BestHTTP

    When I connect to a node.js socket.io server on localhost with this asset, I get a disconnect and connect roughly every 1-2 seconds. This is occurring in-editor on pc.

    2 odd things:
    1. BestHTTP works fine with an external socket.io server like https://socket-io-chat.now.sh/socket.io/
    2. Other local socket.io test tools like http://appsaloon.github.io/socket.io-tester/ connect to my server with no issues.

    The problem seems to be between my server and BestHTTP only. Just bought this asset and I really would like to get it working.
     
  22. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @owlmazing

    How you are setting up for the local server? What url are you using?
    You set the plugins logging to verbose, it will log out a lot of thing most probably the reason why it's reconnecting too:
    Code (CSharp):
    1. BestHTTP.HTTPManager.Logger.Level = BestHTTP.Logger.Loglevels.All;
    You can send the logs to me here on the forums or in a mail.
     
  23. othercrow

    othercrow

    Joined:
    Oct 19, 2013
    Posts:
    15
    It's a basic server pretty much straight out of the socket.io demo.
    I've sent the whole thing along with editor logs by email.

    Code (JavaScript):
    1. var app = require('express')();
    2. var http = require('http').Server(app);
    3. var io = require('socket.io')(http);
    4.  
    5. io.on('connection', function(socket){
    6.   console.log('a user connected');
    7.   socket.on('disconnect', function() {
    8.       console.log('a user disconnected');
    9.   });
    10. });
    11.  
    12. http.listen(3000, function(){
    13.   console.log('listening on *:3000');
    14. });
     
  24. auroxi

    auroxi

    Joined:
    Dec 31, 2012
    Posts:
    82
    I've just switched over to Best HTTP Pro for all of my SignalR communication. Could there be some clarification on the reconnection logic here?

    Will it attempt to reconnect on disconnection only once after the hubConnection.ReconnectDelay, or will it keep trying every ReconnectDelay indefinitely?

    I have attempted to disconnect for 5 minutes, plug my internet back in and then hub.Call("whatever","test1") and it fails. How can I attempt to constantly reconnect every X seconds if the connection is down? Or is ReconnectDelay supposed to handle that logic? It may be something that has gone wrong on the server side but I would like to be clear on how this works from a Unity/client perspective.

    Thanks
     
  25. carsanlop

    carsanlop

    Joined:
    Dec 12, 2017
    Posts:
    9
    @owlmazing @BestHTTP

    Allow me to step in. I came to this thread to report a bug regarding the very same problem. I was getting connected and disconnected every few seconds.

    It turned out that the logic in SocketManager class is flawed. On previous versions of socket.io (1.x) the pingTimeout is 60000, and the pingInterval is 25000. With these settings (ping timeout higher than interval) the plugin works as expected. However, when using the default values for socket.io 2.x, which is pingTimeout = 5000 and pingInterval = 25000 (ping timeout lower than interval) the SocketManager class keeps disconnecting because the heartbeat is failing. You could reproduce it with a brand new socket.io installation without changing any configuration.

    One workaround is changing the values on the server. But the code fix is also very easy.

    1- Add a new bool private field:


    /// <summary>
    /// Whether the connection is waiting for a ping response.
    /// </summary>
    private bool IsWaitingPong;


    2- Set the bool the false whenever we receive a Pong event:


    case TransportEventTypes.Pong:
    LastPongReceived = DateTime.UtcNow;
    IsWaitingPong = false;
    break;


    3- Set the bool to true whenever we send a Ping event:

    // It's time to send out a ping event to the server
    if (DateTime.UtcNow - LastHeartbeat > Handshake.PingInterval)
    {
    (this as IManager).SendPacket(new Packet(TransportEventTypes.Ping, SocketIOEventTypes.Unknown, "/", string.Empty));

    LastHeartbeat = DateTime.UtcNow;
    IsWaitingPong = true;
    }


    4- Change the reconnect condition so it uses both the heartbeat time and only checks when we are waiting for a Pong response:



    if (IsWaitingPong && DateTime.UtcNow - LastHeartbeat > Handshake.PingTimeout)
    {
    (this as IManager).TryToReconnect();
    }


    Forgive me if this solution is actually unrelated to your problem. Worth testing, though, especially simply changing the timeout values in the server. And anyway, I think the login should change in the next release.
     
  26. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @auroxi

    When a connection error is detected the plugin will
    1.) wait ReconnectDelay time before a reconnect attempt.
    2.) If this attempt is failed, it will wait another ReconnectDelay for a new attempt
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @carsanlop

    I think your code fix is the correct one. If you don't mind, i might use your code too.

    Code (CSharp):
    1. And anyway, I think the login should change in the next release.
    Can you elaborate more on this?
     
  28. auroxi

    auroxi

    Joined:
    Dec 31, 2012
    Posts:
    82
    Does 2 then go back to 1, so that it indefinitely attempts to reconnect? So if the ReconnectDelay is set to 5 seconds, I can be disconnected for 3 minutes and then at roughly 3 minutes and 5 seconds it will connect? Or does it just try to reconnect twice?
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @auroxi

    The negotiation data contains a DisconnectTimeout value too. If it set to 25 sec, reconnectDelay to 5 sec, it will try to reconnect about (DisconnectTimeout / reconnectDelay) = 5 times before it gives up.
     
  30. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @auroxi

    DisconnectTimeout / ReconnectDelay is the theoretical maximum, actutal reconnect attempts will be lower then this.
     
  31. carsanlop

    carsanlop

    Joined:
    Dec 12, 2017
    Posts:
    9
    Sorry, a typo. I meant that the logic (not login) should change in order to accomodate the new ping default values, whether with my solution or with another (maybe it is possible to do it without a bool, with pure datetime comparisons).

    Of course you can use the code, glad to be of help. Although you probably know, keep in mind that there is also a ping sent on transport upgrade (WebSocketTransport.OnOpen) that is apparently answered by a "Noop" event, so I did not modify anything there.
     
  32. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @carsanlop

    Thanks for the clarification and code donation.

    I treat the successful protocol opening as ping-pong pair. That's the point where LastHeartbeat is set to the current time first.
     
  33. UnityBLI

    UnityBLI

    Joined:
    Apr 14, 2014
    Posts:
    7
    What is the most recent Socket.IO version that this has been tested with? In the description on the asset store it says "Compliance with the latest (1.3.+) Socket.IO implementation", but in the online documentation it says "Compatible with the latest Socket.IO specification". I wasn't successful using the latest 2.* version, it kept reconnecting, but by downgrading to 1.3.* the same code started working as expected. You may want to update the documentation to call out that it requires Socket.IO server 1.3.* if that is the case.
     
  34. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
  35. BestHTTP

    BestHTTP

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

    Private messages are disabled for your profile.
     
  36. UnityBLI

    UnityBLI

    Joined:
    Apr 14, 2014
    Posts:
    7
    Thanks, I'm good. I have control over the server, so I just downgraded, which is an acceptable solution in this case. I imagine we'll see that update in an upcoming release?
     
  37. BestHTTP

    BestHTTP

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

    Yes, it will be in the next release. I hope it will be out next week.
     
  38. NawarRajab

    NawarRajab

    Joined:
    Aug 23, 2017
    Posts:
    18
    Hi, I'm using BestHTTP Socket.IO implementation. I was wondering how I can inject mock messages from the server. What I want to do is to click a button in Unity that passes a json string so my game thinks it came from the server. This would help me in development and debugging.
     
  39. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @NawarRajab

    That's quite easy, basically you have to create a Packet manually and pass it to the socket manager:
    Code (CSharp):
    1. SocketOptions options = new SocketOptions();
    2. options.ConnectWith = BestHTTP.SocketIO.Transports.TransportTypes.WebSocket;
    3.  
    4. var manager = new SocketManager(new Uri("http://localhost:3000/socket.io/"), options);
    5.  
    6. manager.Socket.On(SocketIOEventTypes.Connect, (s, p, a) =>
    7. {
    8.     manager.Socket.On("MyMessage", (socket, packet, args) =>
    9.     {
    10.         for (int i = 0; i < args.Length; ++i)
    11.             Debug.Log(args[i].ToString());
    12.     });
    13.     object[] message = new object[] { "MyMessage", "string arg", 1337, new Person { Name = "Mr. Smith", Age = 33 } };
    14.     string payload = LitJson.JsonMapper.ToJson(message);
    15.  
    16.     Packet inject = new Packet(TransportEventTypes.Message, SocketIOEventTypes.Event, "/", payload);
    17.  
    18.     (manager as IManager).OnPacket(inject);
    19. });
     
  40. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @NawarRajab

    As the callbacks receiving the packets as their second argument, you can capture real data came from the server and play it back later.
    You can also call the packet's Encode to make a string from it and you can save it to disk, and load it and play back in another session.

    Making a mock transport to fake and play back a whole session could be done too, but that would more work to make transports pluggable.
     
  41. NawarRajab

    NawarRajab

    Joined:
    Aug 23, 2017
    Posts:
    18
    Thanks for the prompt response! it works!
    just for the record, since I already have a server script. All I needed to do is call the following from a button and make sure it's connected to a server first.
    Code (CSharp):
    1.   public void SendMsg()
    2.     {
    3.         var manager = FindObjectOfType<ServerControl>().managerIO;
    4.  
    5.         object[] message = new object[] { "set", "string arg", 1337, new SpawnConfiguration { playAreaName = "Mr. Smith", num = 33 } };
    6.         string payload = LitJson.JsonMapper.ToJson(message);
    7.  
    8.         Packet inject = new Packet(TransportEventTypes.Message, SocketIOEventTypes.Event, "/", payload);
    9.  
    10.         (manager as IManager).OnPacket(inject);
    11. }
     
  42. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    New version uploaded to the store waiting for Unity's approval.

    Basic version of the plugin is deprecated!
    It required too much time to support while its sales are very low. The Pro version however now contains .csproj files instead of the precompiled dlls, so now anyone can compile a dll from the sources. (Or alternately .asmdef files can be used starting from Unity 2017.3 speeding up project recompilation.)

    Also, I made sure that upgrading from Basic to Pro is free for an entire year.

    Another change is that the package has a new protocol: SignalR Core. I release it as preview, it has no documentation or samples yet.
    The release note about it is written a long time ago, it works with the current preview2 too.

    Here are the release notes:
    1.10.4 (2018.04.15)
    • General
      • [Improvement] csproj files added to the package to generate dlls
      • [Improvement] Improved compatibilty with other packages that are have theirs own Utility class in the root namespace.
      • [Improvement] Improved compatibility with the Experimental (.NET 4.6) runtime
      • [Improvement] Using the HTTPRequest's CustomTLSServerNameList property now it's possible to add custom SNIs
      • [Bugfix] Decompressor used during streaming will buffer up data if necessary to avoid a GZip exception.
      • [Bugfix] Removed unnecessary logging in the HTTPUpdateDelegator
      • [Bugfix] TLS SNIs will not be sent if the host is an IPv4 or IPv6 address
      • [Bugfix] Digest authentication failed with the proxy
    • WebSocket
      • [Improvement] Now it's possible to close the websocket before it connects
      • [Improvement] New State property to access the websocket's state
      • [Bugfix] [WebGL] HTTPManager.Setup() isn't called when only the WebSocket protocol is used
    • SocketIO
      • [Bugfix] proper pingTimeout implementation (thanks @carsanlop for the code!)
    • SignalR
      • [Bugfix] It will not try to reconnect after leaving Unity's play mode.
    • SignalRCore
      • [New Feature] New SignalR Core implementation for SignalRCore 1.0.0-alpha2
     
    Last edited: Apr 15, 2018
    VOTRUBEC, carsanlop and Cromfeli like this.
  43. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    197
    Tivadar you are the best! Keep up the great work :cool:
     
  44. Mkarena

    Mkarena

    Joined:
    Oct 15, 2015
    Posts:
    4
    Hi,

    I have a parsing error that occurs time to time (sometimes it works, sometimes not but the server side code is the same...)

    ["match",{"status":"MATCH_FOUND","err":"é"}
    UnityEngine.Debug:Log(Object)

    It misses the closing bracket apparently.

    The server side code is:

    foundMatch.joueurs.a.socket.emit("match", {status: "MATCH_FOUND", err: "match trouvé"});

    And my unity code is:

    manager.Socket.On("match", OnMatchReceived, true);

    void OnMatchReceived(Socket socket, Packet packet, params object[] args)
    {
    Debug.Log(packet);
    }

    Thanks for help


    EDIT

    it seems its not woking due to french accent "é" in the payload...
     
    Last edited: Apr 16, 2018
  45. Mkarena

    Mkarena

    Joined:
    Oct 15, 2015
    Posts:
    4
    @BestHTTP

    Could you send me the fix for the infitinite disconnections/reconnections?

    It even occurs with the 1.3+ versions. Everything is fine server-side tho.

    thanks
     
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @Mkarena

    Can you try out with full websocket? I see a possible problem parsing packets when the polling transport is used.

    You can use websockets from the beginning like this:
    Code (CSharp):
    1. SocketOptions options = new SocketOptions();
    2. options.ConnectWith = BestHTTP.SocketIO.Transports.TransportTypes.WebSocket;
    3. var manager = new SocketManager(new Uri("http://localhost:3000/socket.io/"), options);
    4.  
    5. manager.Socket.On("match", (socket, packet, args) =>
    6. {
    7.     Debug.Log(packet.ToString());
    8. });
     
  47. JinhoonKim_dw

    JinhoonKim_dw

    Joined:
    Mar 16, 2018
    Posts:
    2
    @BestHTTP

    I'm trying to fix some memory bump with downloading huge assets with BestHTTP, thanks to UseStreaming=true.
    But this causes unacceptable slow-down compared to previous WWW method, and I have no clue.
    With our CDN, WWW pulls off whopping 50~80Mb/s compared to BestHTTP struggling at 8Mb/s.
    The 80Mb/s was not a cache-thing - double checked with browser and terminal.

    Still using BestHTTP 1.9.12, wondering if upgrading to recent version would make any difference. The project is on Unity 5.3.4p.
    If you have any advice on improving download speed/bandwidth with BestHTTP, I'd appreciate some tips.
     
  48. dev_runeofdark

    dev_runeofdark

    Joined:
    Oct 27, 2016
    Posts:
    10
    @BestHTTP

    when I import the new release in unity2017.3.1p4, I got 79 errors and 657 warnings about conflicts. when I open the csproj for unity2017.2 and up both editor and uwp I see that I am missing all references from the unity dll's. Do you know where I can find this dll's? At the images you see a part of the warnings and all the errors.

    errors_1.PNG errors_2.PNG errors_3.PNG errors_4.PNG warnings_1.PNG
     
  49. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @JinhoonKim_dw

    There are small differences between WWW/UnityWebRequest and BestHTTP that will add up:
    1. The plugin is written in c#, while WWW/UnityWebRequest is in native code. The plugin always suffer from overheads from the language and the mono/unity framework and these will add up quickly:
      1. range checks for array element access
      2. boxing – unboxing
      3. null checking for every reference type access to thrown NullReferenceException in case of a null value
      4. slower string operations (you can guess with a textual protocol like HTTP there’s a lot of them )
      5. slower delegate calls
    2. Don’t know whether you use secure connections (https://) or not. If so, decryption all of the data is the most CPU intensive one, especially on mobile devices. The plugin uses BouncyCastle instead of the built in SslStream, as the later one is quite buggy (although i think it wouldn't be quicker).
    3. In the end, almost all data must be go through a native->managed (like receiving data from the native socket) or managed->native (passing data to the native socket) boundary, that may require marshalling.
    4. BestHTTP operates on background threads.
    5. GC will pause all managed threads to do garbage collection and to compress used memory.
    WWW/UnityWebRequest will do all the things in native code (most probably calling OS libraries on mobile platforms so even less layers to go back and forth) and will just pass the data to the managed side when it’s done.
     
  50. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,383
    @dev_runeofdark

    I would recommend to delete all BestHTTP related folders (\Best HTTP (Pro)\ and/or \Best HTTP (Basic)\) and reimport it again.

    For the .csproj ones, you have to fix the path by editing the .csproj itself or in Visual Studio.

    But, if you compile dlls from the source, you have to use on or the other. If you keep both the dlls and the source files in your unity project you will get the same errors and warnings as on your screenshots!