Search Unity

Best HTTP Released

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

  1. BestHTTP

    BestHTTP

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

    In short: Yes.
    With more detail/explanation: The plugin will request a keep-alive connection by default and will reuse it as much as it just can. When a connection is idle for a specified time it will close the it to free up server and client resources.
    The plugin also respects and uses the server-sent Keep-Alive header's Timeout value to
     
  2. Davide1104

    Davide1104

    Joined:
    Jun 12, 2013
    Posts:
    38
  3. kyunik

    kyunik

    Joined:
    Dec 3, 2013
    Posts:
    2
    Hi,
    Using the pre-compiled library does not work in Editor.
    I have to use pre-compiled. Because my library project(Editor Extension) reference your library.
    Is there a solution?
     
  4. BestHTTP

    BestHTTP

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

    Thanks for the feedback, I'm reworking my demo page currently, sorry about it.
    You can drop the SampleSelector component to a GameObject in any scene, it doesn't require any setup. The examples are located in the \Assets\Best HTTP (Pro)\Examples\ folder.
     
  5. BestHTTP

    BestHTTP

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

    If you have to use the precompiled dlls than you can call the HTTPManager.OnUpdate periodically:
    Code (CSharp):
    1. using System;
    2.  
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. using BestHTTP;
    7.  
    8. public class EditorTest : EditorWindow
    9. {
    10.     [MenuItem("Window/Editor Test")]
    11.     public static void Init()
    12.     {
    13.         EditorWindow.GetWindow(typeof(EditorTest));
    14.     }
    15.  
    16.     void OnGUI()
    17.     {
    18.         HTTPManager.OnUpdate();
    19.  
    20.         if (GUILayout.Button("Send Request"))
    21.             new HTTPRequest(new Uri("http://httpbin.org/delay/5"), (req, resp) => Debug.Log(resp.DataAsText)).Send();
    22.  
    23.         // Request for a new OnGUI event
    24.         this.Repaint();
    25.     }
    26. }
     
  6. shoo

    shoo

    Joined:
    Nov 19, 2012
    Posts:
    67
    Hello! I am not experienced with WebSockets.
    I am trying to use https://www.npmjs.com/package/ws package to handle websockets on server side. But instead of connection, Best HTTP returns this error:
    Code (CSharp):
    1. System.IO.IOException: Internal TLS error, this could be an attack
    2.   at Org.BouncyCastle.Crypto.Tls.TlsProtocol.FailWithError (Byte alertLevel, Byte alertDescription, System.String message, System.Exception cause) [0x0004a] in C:\Work\UnityProjects\SocketIO\Assets\Best HTTP (Pro)\BestHTTP\SecureProtocol\crypto\tls\TlsProtocol.cs:819
    3.   at Org.BouncyCastle.Crypto.Tls.TlsProtocol.SafeReadRecord () [0x00051] in C:\Work\UnityProjects\SocketIO\Assets\Best HTTP (Pro)\BestHTTP\SecureProtocol\crypto\tls\TlsProtocol.cs:510
    4.   at Org.BouncyCastle.Crypto.Tls.TlsProtocol.BlockForHandshake () [0x0001d] in C:\Work\UnityProjects\SocketIO\Assets\Best HTTP (Pro)\BestHTTP\SecureProtocol\crypto\tls\TlsProtocol.cs:177
    5.   at Org.BouncyCastle.Crypto.Tls.TlsClientProtocol.Connect (TlsClient tlsClient) [0x000df] in C:\Work\UnityProjects\SocketIO\Assets\Best HTTP (Pro)\BestHTTP\SecureProtocol\crypto\tls\TlsClientProtocol.cs:111
    6.   at BestHTTP.HTTPConnection.Connect () [0x005cd] in C:\Work\UnityProjects\SocketIO\Assets\Best HTTP (Pro)\BestHTTP\HTTPConnection.cs:616
    7.   at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x0008a] in C:\Work\UnityProjects\SocketIO\Assets\Best HTTP (Pro)\BestHTTP\HTTPConnection.cs:186
    8. UnityEngine.Debug:Log(Object)
    9. Chat:OnError(WebSocket, Exception) (at Assets/Chat.cs:39)
    10. BestHTTP.WebSocket.WebSocket:OnInternalRequestCallback(HTTPRequest, HTTPResponse) (at Assets/Best HTTP (Pro)/BestHTTP/WebSocket/WebSocket.cs:316)
    11. BestHTTP.HTTPRequest:CallCallback() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPRequest.cs:1240)
    12. BestHTTP.ConnectionBase:HandleCallback() (at Assets/Best HTTP (Pro)/BestHTTP/Connections/ConnectionBase.cs:171)
    13. BestHTTP.HTTPManager:OnUpdate() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPManager.cs:634)
    14. BestHTTP.HTTPUpdateDelegator:Update() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPUpdateDelegator.cs:166)
    15.  
    My client code is simple:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using BestHTTP.SocketIO;
    4. using System;
    5. using BestHTTP.WebSocket;
    6. using BestHTTP;
    7.  
    8. public class Chat : MonoBehaviour {
    9.  
    10.     private WebSocket webSocket;
    11.  
    12.     void Start () {
    13.         // HTTPManager.UseAlternateSSLDefaultValue = false;
    14.         webSocket = new WebSocket(new Uri("wss://localhost:3000/"));
    15.         webSocket.OnOpen = OnOpen;
    16.         webSocket.OnMessage = OnMessage;
    17.         webSocket.OnError = OnError;
    18.         webSocket.Open();
    19.     }
    20.  
    21.     void OnDestroy()
    22.     {
    23.         webSocket.Close();
    24.     }
    25.  
    26.     void OnOpen(WebSocket websocket)
    27.     {
    28.         Debug.Log("WebSocket open!");
    29.     }
    30.  
    31.     void OnMessage(WebSocket websocket, string message)
    32.     {
    33.         Debug.Log(message);
    34.     }
    35.  
    36.     void OnError(WebSocket ws, Exception ex)
    37.     {
    38.         Debug.Log("An error occured!");
    39.         Debug.Log(ex);
    40.     }
    41.  
    42. }
    43.  
    Client connection via browser work, but there is always error when using Unity + Best HTTP.
    What could be the problem in my case?
     
  7. BestHTTP

    BestHTTP

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

    Is your locally hosted websocket is configured to handle secure connections? You defined the uri as WSS:// so it will try to use SSL/TLS to connect to your server. But to succeed your server must be configured so too.
    It's very likely to with just WS:// will work correctly:
    Code (CSharp):
    1. webSocket = new WebSocket(new Uri("ws://localhost:3000/"));
     
    shoo likes this.
  8. navnahn

    navnahn

    Joined:
    Mar 2, 2017
    Posts:
    7
    @BestHTTP
    I got this error from my project:
    Can you suggest me some ideas for this problem?
     
  9. BestHTTP

    BestHTTP

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

    The TCP connection is closed somewhere. For example, a badly configured server can close a long running TCP connection. Or, with poor connectivity the OS will detect problems and close them.
     
  10. jeunetoujour

    jeunetoujour

    Joined:
    Apr 4, 2017
    Posts:
    1
    Does this network stack support TLS 1.1/1.2 for POST requests? Mono/Unity seem to be stuck at 1.0 and I need 1.1+.
    @BestHTTP
     
  11. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
  12. alvaro-em

    alvaro-em

    Joined:
    Feb 23, 2012
    Posts:
    77
    Hi! I have upgraded from Unity 5.4.1 to Unity 5.4.5. After that, some of my requests are failing with this strange message:

    Request Finished with Error! inflating: rc=276446736 msg=

    at BestHTTP.Decompression.Zlib.ZlibBaseStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0

    at BestHTTP.Decompression.Zlib.GZipStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0

    at BestHTTP.HTTPResponse.DecodeStream (System.IO.MemoryStream streamToDecode) [0x00000] in <filename unknown>:0

    at BestHTTP.HTTPResponse.ReadRaw (System.IO.Stream stream, Int32 contentLength) [0x00000] in <filename unknown>:0

    at BestHTTP.HTTPResponse.ReadPayload (Int32 forceReadRawContentLength) [0x00000] in <filename unknown>:0

    at BestHTTP.HTTPResponse.Receive (Int32 forceReadRawContentLength, Boolean readPayloadData) [0x00000] in <filename unknown>:0

    at BestHTTP.HTTPConnection.Receive () [0x00000] in <filename unknown>:0

    at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x00000] in <filename unknown>:0

    I thought it could be a version issue, so I update to the latets Best Http available version (1.9.17) but the issue is still present. Currently I have only found the issue on iOS. I will test the Android version in the next few hours. Until that, any guess on what could be the problem?

    Thank you in advance!
     
  13. navnahn

    navnahn

    Joined:
    Mar 2, 2017
    Posts:
    7
    @BestHTTP
    Can you show me more detail about "a badly configured server can close a long running TCP connection."
    I make sure that the connection on client is good.
     
  14. alvaro-em

    alvaro-em

    Joined:
    Feb 23, 2012
    Posts:
    77
    I contacted the developer by mail and he had this solved with a workaround in a matter of minutes. It seems to be an ILC2CPP bug. The workaround to this issue is adding this line to the request header:

    request.SetHeader("Accept-Encoding", "identity");

    I hope this helps.
     
  15. Genom

    Genom

    Joined:
    Dec 2, 2014
    Posts:
    86
    Hi @BestHTTP, this is a great library and mandatory for me : )

    I am now trying to use Signalr functionality and I am finding a very weird bheaviour: when I try to open the connection it works perfectly in all platforms except in Android, which only works if the device is in LAN (wifi) but with mobile data it get the response :"not a valid websocket request", and after a minute more or less I see that it finally connects (debuggin the server it gets into the Hub) and I see in the client my message "Connected to the Signalr server!" anyway the subscripted method is never coming into.

    I've tried this with Webgl and it works perfectly (without wifi), here you are the code.

    Note: I've tried again, sharing data connection from another mobile and then it works, so it must be something (in android besthttp dll) that works fine when it is connected to a LAN but it is not working when it is consuming 4G. I've tried it with an iPad but I had not 4g so I don't know if it works in iOS. In webgl it does work perfectly.

    public void TestSignalR(string url)
    {
    var uri = new Uri(url);
    var signalRConnection = new Connection(uri, "SyncHub");

    signalRConnection.OnConnected += (con) =>
    {
    Result.text = "Connected to the SignalR server!";
    Debug.Log("Connected to the SignalR server!");
    var hub = signalRConnection["SyncHub"];

    hub.On("SayHello", (h, msg)=>
    {
    Debug.Log(msg.Arguments[0]);
    });


    hub.On("SyncChanges", (h, msg) =>
    {
    var input = msg.Arguments[0].ToString();
    ProcessChanges(input);
    Debug.Log(input);
    });


    hub.Call("Send", "hola desde Unity!");

    hub.Call("RegisterClient", ClientGlobals.ClientDeviceId);
    };
    signalRConnection.OnError += (conn, err) =>
    {
    Result.text = "Error: " + err;
    Debug.Log("Error: " + err);
    };

    signalRConnection.Open();
    }

    do you have any idea what it can be?

    regards!
     
    Last edited: Apr 7, 2017
  16. BestHTTP

    BestHTTP

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

    A WebSocket connection is just a plain old HTTP/1.1 request-response, but it will do additional sending and receiving. But, webservers can't distinguish between websocket and non-websocket connections, so all rules are applied to them too:
    "By default, the connection will be closed if the proxied server does not transmit any data within 60 seconds. This timeout can be increased with the proxy_read_timeout directive. Alternatively, the proxied server can be configured to periodically send WebSocket ping frames to reset the timeout and check if the connection is still alive."
    From WebSocket Proxying.
     
  17. BestHTTP

    BestHTTP

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

    That's interesting, there's no Android specific code in the plugin, it runs the same code as on iOS and on other platforms (WebGL and Windows Phone has different code paths).

    Tried out on my Android phone wifi turned off, but it could connect the first time.

    Is it possible to send me the logs after you added this setting?
    Code (CSharp):
    1. BestHTTP.HTTPManager.Logger.Level = BestHTTP.Logger.Loglevels.All;
     
  18. Genom

    Genom

    Joined:
    Dec 2, 2014
    Posts:
    86
    Sure, but how can I get the output log from the mobile? do I have to print it somehow or send it to my rest service?

    Btw, I am calling the Signalr after I was using the Http post in other part of the the code (once I get the post reponse I open the signalr connection) what is weird is that it works in Lan, and in webgl it works always, maybe because a dispose?
     
  19. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Genom
    You can use Android Device Monitor (through the Android Studio's Tools\Android\Android Device Monitor menu item).
    If you build a development build, it will display its pid, and you can narrow down the log to see only those entries. Then you can select all lines then save it:
    upload_2017-4-8_13-29-13.png
     
  20. Genom

    Genom

    Joined:
    Dec 2, 2014
    Posts:
    86
    Hi @BestHTTP thanks for you answer, I'll install it and try what you ask. I have prepared as weel a simple test, I send you the project and the apk in a personal email, as the forum doesn't allow me to send big files. It has an app.cs that tries the connection against my server, you'll see how it connects when it is in LAN but not when you turn of the wifi, as mentioned.

    I can discard any influence of my other code, as in the test there is only the signarl connections.

    It is a very werid error, indeed. Maybe related to my Unity version? I alreqady checked to bring the latest version of BestHttp

    Edit: I finally uploaded to dropbox, here you are the links

    Unity Project: https://www.dropbox.com/pri/get/Sig...ADCtBh3v6NtAR9tm7VBKfyO7U4u5btXLxsOkMmiTaKtcg

    APK: https://www.dropbox.com/pri/get/tes...AAa82h3jou7nQVf4RUIltY_McvAQEhjdA8q9IXXgOaLww


    thanks!
     
    Last edited: Apr 10, 2017
  21. BestHTTP

    BestHTTP

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

    Thanks for the test project, unfortunately I get an error page for those links.
     
  22. Genom

    Genom

    Joined:
    Dec 2, 2014
    Posts:
    86
  23. shoo

    shoo

    Joined:
    Nov 19, 2012
    Posts:
    67
    I just wonder, could BestHTTP be used as server for WebSockets(with no HTTP support, just WS)?
     
    Last edited: Apr 11, 2017
  24. BestHTTP

    BestHTTP

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

    Thanks again, I could reproduce your issue.
    As the plugin sends the very same data as it would on other network types, I suspect that the error lies somewhere else.
    It would really good to know why the server considers these requests as a non-websocket one.

    In the SignalR troubleshooting page i found this:
    "InvalidOperationException: Not a valid web socket request.
    This error may occur if the WebSocket protocol is used, but the network proxy is modifying the request headers. The solution is to configure the proxy to allow WebSocket on port 80.

    The code that throws this error:
    Code (CSharp):
    1. private Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
    2. {
    3.     var accept = _context.Environment.Get<Action<IDictionary<string, object>, WebSocketFunc>>(OwinConstants.WebSocketAccept);
    4.  
    5.     if (accept == null)
    6.     {
    7.         // Bad Request
    8.         _context.Response.StatusCode = 400;
    9.         return _context.Response.End(Resources.Error_NotWebSocketRequest);
    10.     }
    11.  
    12.     var handler = new OwinWebSocketHandler(callback, _maxIncomingMessageSize);
    13.     accept(null, handler.ProcessRequest);
    14.     return TaskAsyncHelper.Empty;
    15. }
     
  25. BestHTTP

    BestHTTP

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

    No, there are no server capabilities in the plugin.
     
  26. Genom

    Genom

    Joined:
    Dec 2, 2014
    Posts:
    86
    Hi @BestHTTP, I guess I know what can be happening, I have that server under a Url Rewrite, so there is a front server receiving all requests to the IP and then redirecting to other machines where the server really are. I didn't even thought about because the WebGL is working properly (without wifi). I'm gonna try to figure out how to do it, although first I'm gonna make a test placing the server in the front one.

    thanks for your help, once we can find a soltion it may be a good idea to add to the documentation.

    regards!

    pd: it would be awesome to add server capabilities as well, we need to do that and we are experimenting with Unity networking classes.
     
  27. Vascoptorres

    Vascoptorres

    Joined:
    Jul 26, 2012
    Posts:
    18
    Hey @BestHTTP , I am having a problem with WebGL. I'm not able to send requests to my server I get this error:

    And on the web console I get this:
    The thing is, I have the CORS headers on the server side, and the same request works when using Unity's WWW class. Am I missing something?
     
  28. BestHTTP

    BestHTTP

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

    The "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:20006/test. (Reason: CORS preflight channel did not succeed)." message is logged by the browser. The plugin and Unity uses the same XmlHTTPRequest implementation.
    Isn't it possible that you tested on two different browsers? FireFox for example more restrictive than Chrome.
     
  29. Genom

    Genom

    Joined:
    Dec 2, 2014
    Posts:
    86
    Hi @BestHTTP more information about the issue:

    - it seems to have nothing to do with the reverse proxy, I've just created another site in the main server with the server code and still the behaviour is the same.

    - the weirdest things are
    1) if I connect my mobile to another wifi source (not the one where the server is, but another mobile with data, or one bar wifi) then it works
    2) when it is running with WebGL it works perfectly no matter where
    3) a while after the error message it finally connects, but not data is ever received from the server
    4) I've been able to create a pure web socket connection in the past with WebSocket-sharp.


    It maybe something related with my ISP (Vodafone) could you please provide a test site that I can use for the test?

    regards!

    pd: I've just found the same issue was happening to another Vodafone user : https://foro.vodafone.es/t5/Android/Conexión-dispositivo-Android-Servidor-Websockets/td-p/257264
     
    Last edited: Apr 12, 2017
  30. Genom

    Genom

    Joined:
    Dec 2, 2014
    Posts:
    86
    Hi again @BestHTTP, finally I made it work using Websocket-sharp for the signalr connection, I made two classes SignalRClient, and SignalrRClient2.

    The first one uses you WebSocket while the second ones uses Websocket-sharp, so I guess it might me a small hidden diference in the way the requests are handled. However, you can see that for Webgl I keep using your SignalR class, I guess it is working because of it uses the XMLHttpRequest (with Websocket-sharp it does not work so maybe there is some forbbiden threading some place causing the browser to stack).

    here you are the link with the project:

    https://www.dropbox.com/s/s5xqkuvvi1soid0/SignalrTest.rar?dl=0

    In the meantime I'll keep using Websocket-sharp for signalr, but it would be suuuuper nice to use only BestHttp : )

    regards!
     
  31. BestHTTP

    BestHTTP

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

    WebGL requires a completely different implementation based on the underlying browser's XmlHttpRequest for HTTP and WebSocket for the WebSocket protocol. Threading is an additional issue, but the main problems are these.

    I will try to debug it out somehow, but can't make a promise on its success.
     
  32. Genom

    Genom

    Joined:
    Dec 2, 2014
    Posts:
    86
    Hi @BestHTTP thanks for your answer, don't worry about the issue I have found a work around combining BestHttp with Websockets-sharp:

    - BestHttp: For Http normal connections (all platforms) and for SignalR (Webgl because it is using XmlHttpRequest)
    - Websocket-sharp: for SignalR creating my own wrapper (all platforms but Webgl)

    There must be something different the way your library is working with Webscocket-sharp that causes the failure, and it must be in the Websockets part (not your signalr client) because I adapted my wrapper to use directly your websocket class and it didn't work.

    If you can fix it I'll remove the use of my wrapper and websocket-sharp as I prefer using yours, much more elegant and tested in general, but in the meantime I can go on with my workaroung.

    regards!
     
  33. roger-yoo

    roger-yoo

    Joined:
    Oct 26, 2014
    Posts:
    8
    I am using socket.io. I want to check latency that is not affected by fps. Is there a way?
     
  34. MikeGrist

    MikeGrist

    Joined:
    Jan 13, 2015
    Posts:
    7
    hi. this is a great asset. thanks.
    I'm having a weird problem, perhaps you can help. I am making a standard http request. e.g. (http://myhost:8080/root/some/resource?query=fred)
    the response is a redirect.
    on windows, the redirect url is fully formed including the domain. e.g.. http://myhost:8080/root/cache/me.htm (checked in OnBeforeRedirect). So far so good, the system works.
    When trying the same thing on iOS the reported redirectURl is a local file file://root/cache/me.htm

    clearly this is the same uri but with the wrong domain (and scheme etc).

    is there something in the settings I can do to fix this? or change something during the OnBeforeRedirect on iOS?
    Or is this a bug you can fix in the plugin perhaps?

    many thanks.
     
  35. BestHTTP

    BestHTTP

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

    There's no built-on support to do it, but I see two ways to add:
    1.) By setting HTTPUpdateDelegator.IsThreaded to true, all callbacks will be dispatched from a thread, instead of a Unity Update function. This way, there will be no additional latency.
    2.) If you have the Pro version of the plugin, you can add it directly to the plugin:
    2.a) The SocketManager.cs already have two (private) fields: LastHeartbeat and LastPongReceived. The first one contains when the last ping message sent out, the later one will contain when the pong message received. You can calculate the difference. There's a catch however as packet handling will be done from a Unity event by default. If HTTPUpdateDelegator.IsThreaded is set to true, these are also dispatched from that thread too.
    2.b) Any custom solution can be made, but the previous is the most straightforward.
     
  36. BestHTTP

    BestHTTP

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

    Hmm, I already seen that the Uri class had a bug for a platform, it can be an another one. I will check it out.
     
    MikeGrist likes this.
  37. BestHTTP

    BestHTTP

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

    Unfortunately couldn't reproduce it.
    Also double checked and this issue should be fixed since v1.9.16:
    1.9.16 (2016.10.24)
    General
    -[Bugfix] Made a workaround for a mono bug where on macOS Uri created a file:// uri from a relative path instead throwing an exception.


    (This workaround is on for every platform, not just macOS.)
     
    MikeGrist likes this.
  38. MikeGrist

    MikeGrist

    Joined:
    Jan 13, 2015
    Posts:
    7
    brilliant thanks.
    Looks like we are running version 1.9.13 so will update.
    thanks for the support.
     
  39. phil-harvey

    phil-harvey

    Joined:
    Aug 27, 2014
    Posts:
    75
    I just got the TSL error connecting to Akamai.

    base "System.IO.IOException: Internal TLS error, this could be an attack\r\n at Org.BouncyCastle.Crypto.Tls.TlsProtocol.FailWithError (Byte alertLevel, Byte alertDescription, System.String message, System.Exception cause) [0x00059] in C:\\projects\\Solitaire-Mobile\\Assets\\Best HTTP (Pro)\\BestHTTP\\SecureProtocol\\crypto\\tls\\TlsProtocol.cs:819 \r\n at Org.BouncyCastle.Crypto.Tls.TlsProtocol.SafeReadRecord () [0x0003d] in C:\\projects\\Solitaire-Mobile\\Assets\\Best HTTP (Pro)\\BestHTTP\\SecureProtocol\\crypto\\tls\\TlsProtocol.cs:502 \r\n at Org.BouncyCastle.Crypto.Tls.TlsProtocol.BlockForHandshake () [0x00023] in C:\\projects\\Solitaire-Mobile\\Assets\\Best HTTP (Pro)\\BestHTTP\\SecureProtocol\\crypto\\tls\\TlsProtocol.cs:177 \r\n at Org.BouncyCastle.Crypto.Tls.TlsClientProtocol.Connect (TlsClient tlsClient) [0x000e5] in C:\\projects\\Solitaire-Mobile\\Assets\\Best HTTP (Pro)\\BestHTTP\\SecureProtocol\\crypto\\tls\\TlsClientProtocol.cs:111 \r\n at BestHTTP.HTTPConnection.Connect () [0x0064c] in C:\\projects\\Solitaire-Mobile\\Assets\\Best HTTP (Pro)\\BestHTTP\\HTTPConnection.cs:616 \r\n at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x00090] in C:\\projects\\Solitaire-Mobile\\Assets\\Best HTTP (Pro)\\BestHTTP\\HTTPConnection.cs:186 " System.SystemException

    connecting to this URL

    https://mindjolt-a.akamaihd.net/dlc/instant-solitaire/static/pc/themes/v4.1/birdnbees
     
  40. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @phil-harvey

    For some reason the default HTTPS handler can't handle this connection. But, when turned off, the request succeed. You can turn off per-request:
    Code (CSharp):
    1. request.UseAlternateSSL = false;
    or globally for all consecutive requests:
    Code (CSharp):
    1. HTTPManager.UseAlternateSSLDefaultValue = false;
     
  41. phil-harvey

    phil-harvey

    Joined:
    Aug 27, 2014
    Posts:
    75
    I used the Define to get it working in the end, very strange.

    Phil
     
  42. Zanderfax

    Zanderfax

    Joined:
    Nov 2, 2016
    Posts:
    25
    Question about packet decode:

    I am getting my data back from my server and the packet has the following format:

    Code (CSharp):
    1.     ["table_list",[{"gameNum":1,"tableID":"1_917747","numPlayers":"2","numRuns":"1"},{"gameNum":2,"tableID":"2_1124221","numPlayers":"4","numRuns":"9"}]]
    I am trying to get the second part into a Playmaker hash table and I can't seem to get the decode right.

    This is the event handler that the packet came from:
    Code (CSharp):
    1.  
    2. void tCTableList(Socket socket, Packet packet, params object[] args)
    3.     {
    4.         Debug.Log("table_list event seen\n");
    5.         Debug.Log(packet);
    6.         playerStateFSM.SendEvent("tC_tables_list");
    7.     }
    8.  
    Is the documentation it says:
    • The args parameter is a variable length array that contains the decoded objects from the packet’s payload data. With the default Json encoder these parameters can be ‘primitive’ types(int, double, string) or list of objects(List<object>) or Dictionary<string, object> for objects.

      I have examined the args[0] which is showing as an object and it appears to be empty.

      So my question is how do I turn the packet into a usable Hashtable or if even more basic is how do I decode non-binary data from a packet?
     
  43. Frp529

    Frp529

    Joined:
    Apr 26, 2017
    Posts:
    3
    @BestHTTP
    Our server is connected through web socket. Console shows error log when close function is called: TCP Stream closed unexpectedly by the remote server
     

    Attached Files:

  44. BestHTTP

    BestHTTP

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

    This was my relevant server code:
    Code (JavaScript):
    1. io.on('connection', function (socket) {
    2.     var table_list = [];
    3.     table_list.push({
    4.         "gameNum": 1,
    5.         "tableID": "1_917747",
    6.         "numPlayers": "2",
    7.         "numRuns": "1"
    8.     });
    9.     table_list.push({
    10.         "gameNum": 2,
    11.         "tableID": "2_1124221",
    12.         "numPlayers": "4",
    13.         "numRuns": "9"
    14.     });
    15.  
    16.     socket.emit('table_list', table_list);
    17. });
    And my callback:
    Code (CSharp):
    1. private void OnTableList(Socket socket, Packet packet, object[] args)
    2. {
    3.   // Args has one element: a list of objects
    4.   List<object> argList = args[0] as List<object>;
    5.   for (int i = 0; i < argList.Count; ++i)
    6.   {
    7.     // grab the nth object
    8.     Dictionary<string, object> tableEntry = argList[i] as Dictionary<string, object>;
    9.  
    10.     // print its fields
    11.     foreach (var field in tableEntry)
    12.       Debug.Log(i + " - " + field.Key + ": " + field.Value);
    13.   }
    14. }
    15.  
    It's printed the fields of the two objects.
     
  45. BestHTTP

    BestHTTP

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

    Hmm, without any additional detail, I can just guess. When the client closes the WS connection it sends out a Close packet and waits for the server's answer (the server should send a Close packet too!), if it didn't send it just closes the TCP connection than this error can happen.
     
  46. Zanderfax

    Zanderfax

    Joined:
    Nov 2, 2016
    Posts:
    25
    The args being a list of objects was the key that I was missing. This works perfectly! Thank you very much!
     
  47. BestHTTP

    BestHTTP

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

    Great!

    The arguments' type depends on what the server sends. In my sample it's an array (of table entries), so it will be a List<object> on the client. If the server would pass a table entry, then it would be a Dictionary<string, object>.
     
  48. BigRedGames

    BigRedGames

    Joined:
    Jun 25, 2016
    Posts:
    48
    Hi @BestHTTP,

    First thing I want thank you by the great Job with this plugin.

    We having a stranger problem with Best Http Pro on our Game. When we are testing the game on Editor or on Android and on IOS directly from Xcode It's working fine, but when we did a deploy to TestFlight the communication with our server stopped working and I don't know what is happening. Looking on the Server Logs the request was received, processed and returned to game with success, but It wasn't received by the game, showing TimeOut error every time.

    We are using the last version of the Best Http Pro with Unity 5.4.3f1.

    Thanks.
     
  49. Deleted User

    Deleted User

    Guest

    Hi,

    Is there anyone experiencing detection of "disconnect" in socket.io module?

    When we are connected; if we switch mobile devices to airplane mode; "disconnect"
    is called approx. 20 seconds later although we set the timeout for 4 secs as below:

    SocketOptions _socketOptions = new SocketOptions();
    _socketOptions.Timeout = TimeSpan.FromMilliseconds(4000);
    _socketOptions.ReconnectionDelay = TimeSpan.FromMilliseconds(1000);
    _socketManager = new SocketManager(new Uri(url), _socketOptions);

    Thanks to BestHttp Staff; I was also replied in gmail, I am writing here if someone else has the same problem. Reply is:

    The TCP channel need some time to detect a lost connection. TCP implementations can send out KeepAlive packets to detect connection anomalies, 20 secs looks like Android’s default. You can try to alter the defaults in the TcpClinet.cs in the \Assets\Best HTTP (Pro)\BestHTTP\PlatformSupport\TcpClient\ folder around lines 467-468.
     
    Last edited by a moderator: Apr 28, 2017
  50. sandcastles

    sandcastles

    Joined:
    Oct 16, 2015
    Posts:
    1
    We in recent days we are seeing all requests timeout when testing BestHTTP Pro through Test Flight, this was not previously the case. Running locally on Xcode on a device, in the editor and on Android devices/Google Play all work - its just Test Flight builds that are completely failing.

    We have just updated to the latest version 1.9.17 (2017.01.29), previously on 1.9.16 and this has not resolved the issue. Is anyone else seeing these issues?