Search Unity

Best HTTP Released

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

  1. Xtremedev

    Xtremedev

    Joined:
    Nov 6, 2015
    Posts:
    5
    BTW - Great asset - has already saved me heaps of time -great value
     
    StephenZepp likes this.
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
  3. jtrice

    jtrice

    Joined:
    Aug 29, 2012
    Posts:
    7
    Awesome asset - already reviewed.. but wish I could repeat it about once a month.

    Running Unity 5.3.3f1
    Just upgraded to 1.9.10

    iOS build is bailing on failure to run UnusedByteCodeStripper2.exe -out

    Any obvious thing you've run into here?
    Thanks
    j

    p.s. - Building on MacOS -- Looks like WebGL also. Any thoughts?
     
    Last edited: Apr 5, 2016
  4. BestHTTP

    BestHTTP

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

    Thank you very much, I really appreciate it!

    v1.9.11 already on its way to the store to fix this, but for now you can edit the link.xml in the \Assets\Best HTTP (Pro)\ folder and copy the content from this post.
     
  5. ivan_barbancic

    ivan_barbancic

    Joined:
    Jul 21, 2015
    Posts:
    3
    Hi,

    Is it possible to create a custom form where I can add a stream as a filed. This stream could be large so I would like to upload that stream in chunks. The only solution that I could think of was to create a custom stream and then insert that form in the custom stream and then upload it with the UploadStream.
    If it is possible I would prefer the first solution because it is more elegant.

    Thanks
     
  6. BestHTTP

    BestHTTP

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

    Well, it would be possible to modify the plugin to accomplish this, but it would require a lot of modification.
    But right now, the plugin expect form data as static and digest authentication wouldn't be usable with this approach as it requires to calculate a hash on the body too. This later I think wouldn't affect you, but i have to consider every possibility.

    Isn't it possible to send your data in a separate request with UploadStream?
     
  7. ivan_barbancic

    ivan_barbancic

    Joined:
    Jul 21, 2015
    Posts:
    3
    It is possible but I was just trying to find a solution to avoid that :).
    Thank you for the information, i will go with a separate request.
     
  8. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    New update is out now in the Asset Store!

    Release notes of this release:
    1.9.11 (2016.04.04)
    • General
      • [Bugfix][WebGL] Fixed a case where http requests truncated under Microsoft Edge
      • [Bugfix] The plugin will work again in editor windows
      • [Bugfix] Multiple fixes around request abortion
    • Server-Sent Events
      • [Bugfix] [WebGL] Newly created event sources will not use the same id(1) over and over
    • Socket.IO
      • [Improvement] Rewrote handshake processing to be able to skip the polling transport
      • [Improvement] Now it’s possible to inform the plugin what transport it should use to connect with through the SocketOptions’ ConnectWith property
      • [Improvement][PollingTransport] Will not force the server to send textual packets
      • [Improvement][PollingTransport] Greatly improved packet parsing speed
      • [Bugfix] The plugin will process messages sent with the handshake data
     
  9. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @phuc hoang

    As you can see it in the release notes, now you can connect with WebSocket transport only:
    Code (CSharp):
    1. SocketOptions options = new SocketOptions();
    2. options.ConnectWith = BestHTTP.SocketIO.Transports.TransportTypes.WebSocket;
    3.  
    4. var manager = new SocketManager(new Uri("http://.../socket.io/"), options);
     
  10. knr_

    knr_

    Joined:
    Nov 17, 2012
    Posts:
    258
    At the moment we are using websocket-csharp and its dynamically allocating memory per frame causing a ton of garbage collection that is causing a huge performance hit that scales with the number of networked objects we are using with it. Does your websocket implementation(s) (I see SignalR in there too) do dynamic allocations that cause garbage collections per frame or is the code "clean"?

    Thanks!
     
  11. BestHTTP

    BestHTTP

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

    As I'm a game developer too, I know how a middleware should be remain in the background and lightweight as much as possible. This is why i try to avoid too much abstractions, and keep memory usage low and reuse as much as I just can. But I still can't say that it's "clean" from memory garbage.
    There are several reason why it's very hard, or even impossible to do so:
    1. If you use HTTPS, the underlying implementation will do memory allocations for reads and writes. They are not created with these principles in mind.
    2. The WebSocket server can send messages in multiple WebSocket Frame. When it decide to do so, the client will not know the final size of the whole data. But the client should represent the data to higher level as a whole, so it has to keep fragments then assemble them into a large buffer.
    3. Buffers can't be reused by the plugin because it doesn't know when the end-user (you) finished using it. It's possible that you are using it, while the plugin thinks it's free to write into it again (you can fire up a coroutine and use the received data and buffer several frames or even seconds after it arrived).
    4. Data length can be anything from 1 bytes to 2 GB, and there is a high chance that consecutive messages will not be the same size.
      1. The plugin would use a pool to get large enough buffers to the messages (lets say, it will grab a 128 bytes length buffer for a 10 bytes message). But as you imagine, in this case you have to keep in mind that you can't use the whole buffer. Some APIs can be used with this approach, but others don't.
        1. You can get an utf8 string with the UTF8.GetString(data, 0, length) call.
        2. You can't load it as a texture. Texture2D's LoadImage will take the whole buffer, you can't inform that it should use only the first 10 bytes of the buffer.
      2. The second approach would use buffers with the expected size, but keeping them would use up memory quickly, specifying a maximum would result in dynamic allocations again.
      3. And there is a problem of uncertainty that whether we can use the buffer again or not.
    5. If you want to use extensions like Per-Message Compression to lower bandwidth requirement, it will produce memory allocations and garbage again.

    So, it would be possible to write a zero allocation websocket implementation (no HTTPS and no extensions), but it would be an unfriendly API that would produce hard to debug bugs. It's easy to optimize something if the use-case is known., but as a framework writer I have to make trade-offs between usability and performance.

    I don't know WebSocket-sharp in detail, so I don't know whether my plugin allocates more or less memory per message.
    However it would be relatively easy to modify my plugin to work as I described in 4.1:
    1. If extensions are disabled there is only one large memory allocation per message (a neglectable amount is allocated per message (2-8 bytes) to read the length of the message if the length is larger than 126 bytes and to read the mask (4 bytes)).
    2. The steps to make it work:
      1. Write a buffer pool. It must be thread safe, though!
      2. Modify the WebSocketFrameReader class to use this newly created pool instead of direct allocation
      3. Modify the WebSocketResponse and WebSocket classes to introduce a new event to dispatch the WebSocketFrameReader instance intself as it contains the real length of the message, or the buffer and the size of the real data.
      4. After the event calls in the WebSocketResponse class, it has to push buffers back to the pool.
      5. A better approach would be to implement the IDisposable interface in the WebSocketResponse class, and when it's not in use anymore call its Dispose() function where the buffer would be pushed back to the pool. This would add the flexibility to the problem I wrote about in point 3.

    With testing and bugfixing I think it can be done in one or two days.
     
  12. Huarez

    Huarez

    Joined:
    Aug 18, 2015
    Posts:
    3
    Hello, in my game we using websockets on facebook we connects to "WSS://myserver.org:8080/mainsocket"; on editor we use "WS://mysecondserver.org:8889/mainsocket" for dev server. now we are trying to port game to ios and want to use same server as on facebook for crossplatform playing, but on ios WSS didnt woking and we tried using WSS on editor it didnt worked too. the error the same:
    [Param]ex.Message = 'The authentication or decryption has failed.'
    [Param]ex.StackTrace = ' at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 '

    what could be the reason of this error?
     
  13. BestHTTP

    BestHTTP

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

    You can try to set the alternate SSL handler:
    Code (CSharp):
    1. BestHTTP.HTTPManager.UseAlternateSSLDefaultValue = true;
    You can call this somewhere in your start-up code.
     
  14. Huarez

    Huarez

    Joined:
    Aug 18, 2015
    Posts:
    3
  15. akstntn

    akstntn

    Joined:
    May 28, 2013
    Posts:
    20
    Hi,
    I am using BestHtttp ( Pro ) and am developing a WebGL game on Unity 5.3.4.
    When I build the game and test it. I got the error "missing : XHR_Create"
    I know BestHtttp supports WebGL as well. Is there any way to fix this issue?
     
  16. BestHTTP

    BestHTTP

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

    In the \Assets\Best HTTP (Pro)\Plugins\WebGL\ folder should be three jslib files. If you can't find them, you may try to reimport the package.
     
  17. akstntn

    akstntn

    Joined:
    May 28, 2013
    Posts:
    20
    Did I say you are a life saver?
    Thank you so much!!
     
  18. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    Do you have any plans to support socket.io rooms, or is there a way I can do it currently? I'm implementing chat in my game, and it'd be handy to be able to join various rooms beneath the /chat namespace (e.g., a guild room, global room, game room, etc.). Rooms are described here, in case you're curious: http://socket.io/docs/rooms-and-namespaces/
     
  19. MathieuH

    MathieuH

    Joined:
    Jan 19, 2016
    Posts:
    1
    Hi,

    I just downloaded this asset from the store (basic version) and do not see anywhere in the documentation or other how to create a local HTTP server. Is this possible using this @BestHTTP?

    Thanks
     
  20. BestHTTP

    BestHTTP

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

    Unfortunately I have no plans to support it in the near future, sorry.
     
  21. BestHTTP

    BestHTTP

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

    Unfortunately, this plugin is http client only, you can't create a http server with it.
     
  22. Comtaler

    Comtaler

    Joined:
    Jul 8, 2015
    Posts:
    7
    I am trying make a build for WebGL with Socket.IO. But I got the following errors:
    The Code I used is:
    Code (CSharp):
    1.         SocketManager socketManager = new SocketManager(new Uri("http://" + "myhostname" + "/socket.io/"));
    2.         socketManager.Socket.On("connect", (Socket socket, Packet packet, object[] args) =>
    3.         {
    4.             Debug.Log("connect");
    5.         });
    6.  
     
  23. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Comtaler
    That file should be deleted.
    I would recommend to delete the /Assets/Libs/Best HTTP (Pro)/ folder and reimport the latest version from the Asset Store.
     
  24. Comtaler

    Comtaler

    Joined:
    Jul 8, 2015
    Posts:
    7
    That fixed the problem. Thanks for the prompt reply
     
  25. sstublic

    sstublic

    Joined:
    Nov 12, 2012
    Posts:
    13
    Hi,

    I'm running into performance issues with BestHTTP Pro.

    1. Running a POST request to localmachine:5000 always takes around 1000ms. By comparison pure WWW request (the same one) from Unity takes around 60ms.

    2. Running a post request to remote server is around 50% slower with BestHTTP than with WWW. (250ms vs 350ms)

    What could be the problem with issue (1)? Where should I start looking?

    Regarding issue (2); is that expected result? BestHTTP request does contain 3 cookies <1kb, but everything else is the same. This performance difference is big enough to use WWW over BestHTTP and that would be a shame.

    Please advise!

    Regards
     
  26. BestHTTP

    BestHTTP

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

    The difference shouldn't be this high, and wasn't experienced slowing like this. You doesn't wrote the size of your post data, converting it might be slow (but not this slow).
    Also, you can try it out without cookies. You can disable them:
    Code (CSharp):
    1. HTTPManager.IsCookiesEnabled = false;
    Also, can you reproduce it with a service like http://httpbin.org/ ? You can use http://httpbin.org/post as an endpoint to send your post data, and receive it back. If it's slow with this too, you can send me a repro project using this uri, so i can take a look on it.
     
  27. sstublic

    sstublic

    Joined:
    Nov 12, 2012
    Posts:
    13
    I tried disabling caching, retries, redirects (max = 0) AND cookies. Results are the same.

    When trying to post to httbin.org/post, both WWW and BestHTTP perform similarly, so we can call this one a problem on my end or the problem with measuring.

    So the problem that remains is posting to localhost

    Since there was no POST payload (url only returned data) I changed it to GET and tried doing both BestHTTP and WWW request via GET method.

    Again, WWW 65ms, BestHTTP 1077ms

    Seems there is some kind of issue with localhost or requests with ports ?
     
  28. BestHTTP

    BestHTTP

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

    Hmm. The plugin itself doesn't walk different code paths based on the host or port.
    My tests most of the time goes through a proxy on localhost, and I connect to local node.js test frequently. more then 1000ms per requests would be very noticeable.
    At this moment I have no clue on this.
     
  29. sstublic

    sstublic

    Joined:
    Nov 12, 2012
    Posts:
    13
  30. oddurmagg

    oddurmagg

    Joined:
    Mar 20, 2013
    Posts:
    19
    I am having troubles getting it to work with a certain proxy, the recording proxy in jmeter.

    I've configured it correctly to work with other proxies which I use for debugging, such as Charles.

    When I setup the jmeter proxy ( I want to record a session to use for load testing ), I get the following error:

    Ex [HTTPRequest]: SendOutTo - Message: 1: Write failure at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
    at System.IO.BinaryWriter.Write (System.Byte[] buffer) [0x0002c] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/BinaryWriter.cs:130
    at BestHTTP.HTTPRequest.SendOutTo (System.IO.Stream stream) [0x0009c] in /Users/oddur/perforce/projects/twodee/trunk/twodeeunity/Assets/Best HTTP (Pro)/BestHTTP/HTTPRequest.cs:1074
    2: Write failure at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
    at System.IO.BinaryWriter.Write (System.Byte[] buffer) [0x0002c] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/BinaryWriter.cs:130
    at BestHTTP.HTTPRequest.SendOutTo (System.IO.Stream stream) [0x0009c] in /Users/oddur/perforce/projects/twodee/trunk/twodeeunity/Assets/Best HTTP (Pro)/BestHTTP/HTTPRequest.cs:1074 StackTrace: at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
    at System.IO.BinaryWriter.Write (System.Byte[] buffer) [0x0002c] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/BinaryWriter.cs:130
    at BestHTTP.HTTPRequest.SendOutTo (System.IO.Stream stream) [0x0009c] in /Users/oddur/perforce/projects/twodee/trunk/twodeeunity/Assets/Best HTTP (Pro)/BestHTTP/HTTPRequest.cs:1074
    UnityEngine.Debug:LogError(Object)
    BestHTTP.Logger.DefaultLogger:Exception(String, String, Exception) (at Assets/Best HTTP (Pro)/BestHTTP/Logger/DefaultLogger.cs:111)
    BestHTTP.HTTPRequest:SendOutTo(Stream) (at Assets/Best HTTP (Pro)/BestHTTP/HTTPRequest.cs:1155)
    BestHTTP.HTTPConnection:ThreadFunc(Object) (at Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:145)

    I can configure regular browsers (chrome) to connect through this proxy through. Any ideas ?
     
  31. vergilcastelo1

    vergilcastelo1

    Joined:
    Jan 28, 2015
    Posts:
    2
    Trying to correctly format the required parameters for adding a new contact in an API but can't seem to get it right. I start with a dictionary and am trying to add the "lists" and "email_addresses" as arrays and turn it into strings before encoding and sending the request.

    Link to the API endpoint http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST

    My code looks like this:
    Code (CSharp):
    1.  List<string> addies = new List<string>();
    2.         addies.Add("{ 'email_address' : 'test@gmail.com' }");
    3.  
    4.         Dictionary<string, string[]> info = new Dictionary<string, string[]>();
    5.         info.Add("lists", new string[]{"'id' : '1475239787' "});
    6.         info.Add("email_addresses",  new string[]{"'email_address' : 'test@gmail.com'"});
    7.        // info.Add("email_address", "test@gmail.com");
    8.        
    9.  
    10.         request.SetHeader("Content-Type", "application/json; charset=UTF-8");
    11.         request.AddHeader("Accept", "application/json");
    12.      
    13.         request.RawData = System.Text.Encoding.UTF8.GetBytes(BestHTTP.JSON.Json.Encode(info));
    14.         request.Send();
    but the server returns 400. Any help would be great.
     
  32. GLeBaTi

    GLeBaTi

    Joined:
    Jan 12, 2013
    Posts:
    54
    Hi. How can I put multiple parameters in socket.io emit?
    Like this:
    socket.emit("game/connect", {game_id: 123, player_id: 1, chat: true});
     
  33. BestHTTP

    BestHTTP

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

    Well, I think it's possible that www bypass the DNS query when the hostname is 'localhost', and will go straight with the '127.0.0.1' IP address.
     
  34. BestHTTP

    BestHTTP

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

    Following this guide, I wasn't able to reproduce this issue:
    upload_2016-5-2_16-54-48.png

    My proxy setup for all proxies that I use(including Charles) is the following:
    Code (CSharp):
    1. BestHTTP.HTTPManager.Proxy = new BestHTTP.HTTPProxy(new Uri("http://localhost:8080"), null, true);
     
  35. BestHTTP

    BestHTTP

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

    You can send it like this:
    Code (CSharp):
    1. class ConnectSetup
    2. {
    3.     public int game_id;
    4.     public int player_id;
    5.     public bool chat;
    6. }
    7.  
    8. var manager = new SocketManager(new Uri("http://.../socket.io/"), options);
    9. // Setup the manager with a more advanced json encoder. This will be able to encode an object instance
    10. manager.Encoder = new BestHTTP.SocketIO.JsonEncoders.LitJsonEncoder();
    11.  
    12. // just pass a ConnectSetup instance to the Emit function, it will encode it and send to the server
    13. socket.Emit("game/connect", new ConnectSetup { game_id = 123, player_id = 1, chat = true });
     
    GLeBaTi likes this.
  36. xyzDave

    xyzDave

    Joined:
    Jun 19, 2014
    Posts:
    24
    Hi, great library, saved me loads of time so far.
    I have a question.
    I'm making sure I have good error handling so the app can be used in bad network areas and retry when we get signal again.
    So, I'm trying to track which of multiple requests fail, so I came across the Tag object to allow tracking of requests (my HTTP requests are all very similar with changes in the field values, which we don't get access to via your library).
    But, when I looked at the Tag object it appears you are now using it as a retry counter in a couple of places (e.g. int retryCount = (int)req.Tag;) - does this mean the Tag object cannot be used by me?

    I need to use it with bad network problems, when it fails, so it worries me as these see to happen only when it fails to contact the server - the same thing I'm trying to log and handle

    thank you.
    dave
     
  37. BestHTTP

    BestHTTP

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

    As I see I only used it in the SignalR implementation's TransportBase class.
    For regular requests you are free to use it. If you want to use it for SignalR requests too, then, well we can find out a good solution.
     
  38. xyzDave

    xyzDave

    Joined:
    Jun 19, 2014
    Posts:
    24
    Ah - thanks for the reply. Just read all about SignalR in your Docs and I'm not using it (and hopefully won't).
    Many thanks (and for the super speedy reply)
    Dave
     
  39. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
  40. shunmugamIP

    shunmugamIP

    Joined:
    Nov 30, 2015
    Posts:
    4
    Hi
    I am using SignalR for fetching data from server,
    WebGl Build working fine in the safari browser
    It is not working firebox browser
    It's throwing error "Unknown error, Maybe CROS problem"
     
  41. BestHTTP

    BestHTTP

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

    You can check your browser's console for additional details. Firefox has a more strict CORS implementation, so it can be the root of this problem.
     
  42. shunmugamIP

    shunmugamIP

    Joined:
    Nov 30, 2015
    Posts:
    4
    Thank you For your reply
    Cross origin is already enabled on the server
    and we placed crossdomain.xml on the server
    <?xml version="1.0"?>
    <cross-domain-policy>
    <allow-access-from domain="*"/>
    </cross-domain-policy>

    Still we are facing issue CROS problem
    Err [NegotiationData]: Negotiation request failed with error: Unknown Error! Maybe a CORS porblem?

    Please assist to solve this issue
    Thanks
     
  43. BestHTTP

    BestHTTP

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

    Is there any error in the console? Can you send (through mail) me a repro-project, or at least an url that I can use to try to reproduce this issue? What version of FireFox are you using?
    Also, Crossdomain.xml has no effect in WebGL builds.
     
  44. mogwhy

    mogwhy

    Joined:
    Nov 20, 2014
    Posts:
    36
    Could you please add a sample usage of JWT to the documentation?
     
    Last edited: May 8, 2016
  45. HelloNan

    HelloNan

    Joined:
    Aug 10, 2012
    Posts:
    18
    Question:

    Code (CSharp):
    1.            
    2. if (IsThreaded)
    3.             {
    4. #if NETFX_CORE
    5.                 Windows.System.Threading.ThreadPool.RunAsync(ThreadFunc);
    6. #else
    7.                 //ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFunc));
    8.                 new Thread(ThreadFunc)
    9.                     .Start();
    10. #endif
    11.             }
    12.  else
    13.           ThreadFunc(null);
    In ConnectionBase.cs line 105, Why //ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFunc)) be
    Comment symbol, Is ThreadPool.QueueUserWorkItem has some bug? or has some
    performance problem on Unity?
     
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @mogwhy
    Thanks for the suggestion, I will try to include samples for authentication. Or maybe writing and including a sample in the package.
     
  47. BestHTTP

    BestHTTP

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

    IL2CPP had some very nasty bugs so I had to switch to plain threads. But now I'm switching back in the next release.
     
  48. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @BestHTTP Is there a way to set the maximum retries a request can make? Also, what would be the best way to tell the requests to retry?

    Finally, I use the WWW class to sometimes load files locally from the hard drive, is this still possible with your plugin, or do I still need to use the WWW class for that?

    EDIT/UPDATE:
    It looks like I was able to load files locally no problem, so that support seems to be there by default.
     
    Last edited: May 10, 2016
  49. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Ben BearFish

    Currently there is no way OOB to precisely control retries. The plugin will retry a non-POST request only once. And there is only way to disable this by setting the request's DisableRetry to true.

    But, you can do something like this:
    Code (CSharp):
    1. class RetryController
    2. {
    3.     public const int MaxRetries = 3;
    4.  
    5.     private HTTPRequest request;
    6.     private int retryCount;
    7.  
    8.     public RetryController(HTTPRequest req)
    9.     {
    10.         this.request = req;
    11.         this.retryCount = 0;
    12.     }
    13.  
    14.     public bool Retry()
    15.     {
    16.         if (++retryCount < MaxRetries)
    17.         {
    18.             this.request.Send();
    19.             return true;
    20.         }
    21.  
    22.         return false;
    23.     }
    24. }
    25.  
    26. Uri uri = new Uri("http://httpbin.org/get");
    27.  
    28. HTTPRequest request = new HTTPRequest(uri, (req, resp) =>
    29.     {
    30.         switch (req.State)
    31.         {
    32.             // The request finished without any problem.
    33.             case HTTPRequestStates.Finished:
    34.                 if (resp.IsSuccess)
    35.                 {
    36.                     Debug.Log("Request Finished Successfully! Response: " + resp.DataAsText);
    37.  
    38.                     // TODO: process downloaded data
    39.                 }
    40.                 else
    41.                 {
    42.                     Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    43.                                                     resp.StatusCode,
    44.                                                     resp.Message,
    45.                                                     resp.DataAsText));
    46.  
    47.                     (req.Tag as RetryController).Retry();
    48.                 }
    49.                 break;
    50.  
    51.             default:
    52.                 (req.Tag as RetryController).Retry();
    53.                 break;
    54.         }
    55.     });
    56.  
    57. // Disable internal retry logic
    58. request.DisableRetry = true;
    59.  
    60. request.Tag = new RetryController(request);
    61.  
    62. request.Send();
    It's a rather basic retry logic, but it should work.
     
  50. Comtaler

    Comtaler

    Joined:
    Jul 8, 2015
    Posts:
    7
    Does Socket.IO's Emit callback have a timeout? In case there is a server error, and the callback is never called. In that case, I need to timeout on the client side. Thanks.