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,455
    @a_d_69

    When no streaming is involved, the plugin allocates large enough memory to store the downloaded data. In your case the server sends the exact length of the content, so the plugin knows how much data comes down. Other than this final buffer, the plugin also allocates an intermediate one to read data in. The reading itself is just a cycle of reading to the intermediate buffer and writing to the final one, the plugin doesn't try to limit the speed in this case.
    When streaming is involved however, the plugin waits if to much data sitting in its internal queue.

    But, because you measured slow speeds in both cases, i think something outside of the plugin affects the speed of the download. I don't know what unity and scripting runtime version are you using, but it might worth a try to change them to see whether the download speed changes.
     
  2. a_d_69

    a_d_69

    Joined:
    Jun 7, 2017
    Posts:
    9
    I am using Unity 2018.3.0f1 and SRV .Net 4.x Equivalent with IL2CPP and compatibility level .Net 4.x.
    I'll try to update Unity. I will inform if I see a changes.
     
  3. rayyybay

    rayyybay

    Joined:
    Oct 26, 2018
    Posts:
    2
    I love the support and dedication towards maintaining this package!

    I have a question concerning my needs:
    Does this package support WebRTC for WebGL builds? If not, are there upcoming plans to implement it?
     
  4. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @raybaybaybay

    WebRTC isn't supported and I don't plan to add it in the foreseeable future.
     
  5. natashkinsasha_unity

    natashkinsasha_unity

    Joined:
    Oct 10, 2017
    Posts:
    1
  6. rayyybay

    rayyybay

    Joined:
    Oct 26, 2018
    Posts:
    2
    @BestHTTP

    I think I found a bug in the Websocket code.

    I've been trying to connect the Websocket sample to my local Websocket server and it isn't working (always responding with HTTP 400 Bad Request).

    My setup is: running Websocket-Sharp library (https://github.com/sta/websocket-sharp) as the server on port 4649.

    In the editor, I'm running your default UI and I connect to "ws://localhost:4649"

    I inspected the logs, and it seems like the handshake is sending "Host: localhost" instead of "Host: localhost:4649"

    I went into the code (BestHTTP/Websocket/Websocket.cs @ line 234) and found this:
    Code (CSharp):
    1. if ((!HTTPProtocolFactory.IsSecureProtocol(uri) && uri.Port != 80) && (HTTPProtocolFactory.IsSecureProtocol(uri) && uri.Port != 443))
    I instead set it to:
    Code (CSharp):
    1. if ((!HTTPProtocolFactory.IsSecureProtocol(uri) && uri.Port != 80) || (HTTPProtocolFactory.IsSecureProtocol(uri) && uri.Port != 443))
    And it worked. Is this a bug or should I not be doing that?

    Thanks!
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @raybaybaybay

    That sounds like a bug. The whole SetHeader("Host", ...) can be deleted so the internal request would be able to set it to the proper value.
    I will fix it in the next update.
     
    rayyybay likes this.
  8. gamebytom

    gamebytom

    Joined:
    Mar 13, 2017
    Posts:
    10
    I'm setting up a SignalR connection - I have it working from a website but can't get it working from Unity. In fact it does work in Unity when I link to your own SignalR test site. But when I duplicated your test site on my own server and get this error:

    Error: Negotiation Request - Connection Timed Out!

    It's an Android device and an Nginx Linux webserver. The Nginx webserver is configured correctly (and I adjusted it for your test site) and the same SignalR configuration works with an Angular website. And the same Android program works perfectly if I simply change the URL to your test server. It is probably only a small or silly error that I've overlooked - but it would be great if you could send over your server configuration files or let me know if you have any hints on how to get this working!
    ---

    update: It was a server configuration issue - the URL wasn't working with 'www' at the front of it.
     
    Last edited: Feb 14, 2019
  9. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    54
    Hi, I'm seeing an odd behavior:
    1. I download an image, it gets cached locally
    2. At runtime, I update that image on my server then delete my local cache entity using HTTPCacheService.DeleteEntity(imageUri);
    3. Download the image again, I get the old version.
    4. Stop the game, Play the game, I get the new version.

    Is there anything I'm missing about the way the local cache works?
    Thanks
     
    Last edited: Feb 15, 2019
  10. BestHTTP

    BestHTTP

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

    I just tried it out and deleted the cached entry. The next request is sent out without the caching headers:
    upload_2019-2-15_8-47-21.png

    While remaining entries are sent with additional headers, and the server responded with a 304-NotModified:
    upload_2019-2-15_8-48-23.png

    You can capture the plugin's requests and the server responses with a proxy like Charles. You can point where is the proxy like this:
    Code (CSharp):
    1. HTTPManager.Proxy = new HTTPProxy(new Uri("http://localhost:8888"), null, true);
     
  11. davewx7

    davewx7

    Joined:
    Feb 25, 2018
    Posts:
    2
    Do server sent events work for a WebGL client? When I try to use them I don't get any error message but don't seem to get any events.
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @davewx7

    Just tried it out, and it works as expected. Could you check your browser's console, maybe it contains error messages or something drive us closer what went wrong.
     
  13. quanjunchen

    quanjunchen

    Joined:
    Oct 12, 2017
    Posts:
    4
    Add data timeout for http request download with streaming when not data received at certain time.
    In my case, i download asset bundles size between severial KB to almost hundred MB.

    Code (CSharp):
    1.          
    2.         void Update()
    3.         {
    4.             if (this.request != null && (DateTime.Now - this.lastUpdateTime).TotalSeconds > 30)
    5.             {
    6.                 // timeout
    7.                 this.request.Abort()
    8.                 this.request = null;
    9.             }
    10.         }
    11.  
    12.         void StartDownload()
    13.         {
    14.             this.request = new HTTPRequest(new Uri(requestUrl), (HTTPRequest req, HTTPResponse resp) => {
    15.                 switch (req.State)
    16.                 {
    17.                     case HTTPRequestStates.Processing:
    18.                         // update last receive time
    19.                         this.lastUpdateTime = DateTime.Now;
    20.                         var frags = resp.GetStreamedFragments();
    21.                         break;
    22.                 }
    23.             });
    24.             request.IsKeepAlive = false;
    25.             request.UseStreaming = true;
    26.             // fragment size according to file size
    27.             if (fileSize < a1KB)
    28.             {
    29.                 request.StreamFragmentSize = a2KB;
    30.             }
    31.             else if (fileSize < b1MB)
    32.             {
    33.                 request.StreamFragmentSize = b2MB;
    34.             }
    35.             else if // and so on
    36.        
    37.  
    But this solution has a problem. If download speed too slow, large file will trigger timeout easily.
    Is there any solution?
     
    Last edited: Feb 18, 2019
  14. pflamant

    pflamant

    Joined:
    Dec 7, 2017
    Posts:
    4
    @BestHTTP

    Hello,
    It seems that the AddField method is escaping double quotes.
    For exemple:
    request.AddField("foo1", "{\"foo2\" : \"bar\"}");

    I would expect the above code to send
    {"foo1" : {"foo2" : "bar"}}

    But instead it will escape the double quotes and send
    {"foo1" : {\"foo2\" : \"bar\"}}


    Is there a way to use AddField without escaping the value ?

    Thank you,
    Pierre
     
    Last edited: Feb 18, 2019
  15. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @quanjunchen

    I think using lastUpdateTime is the best approach, just with a little tweaking. You could set the timeout based on the file size too. Instead of a constant 30 seconds, you can use a larger value for larger file size.
     
  16. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @pflamant

    You can try out sending your form with multipart encoding:
    Code (CSharp):
    1. request.FormUsage = BestHTTP.Forms.HTTPFormUsage.Multipart;
    That will send the data as-is. Your server have to support this encoding however.

    Alternately, you can use single-quotes instead of the double ones. :)
     
  17. pflamant

    pflamant

    Joined:
    Dec 7, 2017
    Posts:
    4
    single-quotes won't be valid JSON :'(

    I ended up setting
    request.RawData
    but that's less practical ;)
     
  18. YODAFAB

    YODAFAB

    Joined:
    Jun 9, 2016
    Posts:
    2
    Hi "BestHTTP",

    I saw that in your description, the library is managing many kinds of proxy, do you manage "proxy auto-config" too ? Like this script:

    function FindProxyForURL(url, host) {
    // our local URLs from the domains below example.com don't need a proxy:
    if (shExpMatch(url,"*.example.com/*")) {return "DIRECT";}
    if (shExpMatch(url, "*.example.com:*/*")) {return "DIRECT";}

    // URLs within this network are accessed through
    // port 8080 on fastproxy.example.com:
    if (isInNet(host, "10.0.0.0", "255.255.248.0")) {
    return "PROXY fastproxy.example.com:8080";
    }

    // All other requests go through port 8080 of proxy.example.com.
    // should that fail to respond, go directly to the WWW:
    return "PROXY proxy.example.com:8080; DIRECT";
    }

    Thanks for your answer.

    Fab
     
  19. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @YODAFAB

    No, that would require to be able to execute javascript.
     
  20. shoo

    shoo

    Joined:
    Nov 19, 2012
    Posts:
    61
    Hello!

    On Android, when app pause, OnMessage callback stops work, but connection still exists. And after app unpause, it receive all messages it got during pause time. Is it possible to drop all this messages without writing my own logic?

    Or maybe it is possible, to drop connection when app paused?
    OnApplicationPause -> if (pause) socket.Close() doesn't works in this case, and disconnect happens only after app unpause
     
  21. BestHTTP

    BestHTTP

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

    This is because unity will not call any Update and other events, so the plugin can't call its callbacks. Threads are not stopped, so it can receive all the server messages (just can't dispatch them...).

    Closing the socket has the same issue.

    One good way would be to handle this is to start a thread on pause and call the plugin's HTTPManager.OnUpdate function from that thread periodically.
    A helper component that you can place on a GameObject would be like this:
    Code (CSharp):
    1. public sealed class BackgroundRunner : MonoBehaviour
    2. {
    3.     public int Frequency = 1000;
    4.  
    5. #if UNITY_ANDROID || UNITY_IOS
    6.     volatile bool isPaused = false;
    7.  
    8.     void OnApplicationFocus(bool hasFocus)
    9.     {
    10.         this.isPaused = !hasFocus;
    11.  
    12.         if (this.isPaused)
    13.             StartThread();
    14.     }
    15.  
    16.     void OnApplicationPause(bool pauseStatus)
    17.     {
    18.         this.isPaused = pauseStatus;
    19.  
    20.         if (this.isPaused)
    21.             StartThread();
    22.     }
    23.  
    24.     void StartThread()
    25.     {
    26.         Thread thread = new Thread(() =>
    27.         {
    28.             while (this.isPaused)
    29.             {
    30.                 // Callbacks will be processed from this call
    31.                 HTTPManager.OnUpdate();
    32.  
    33.                 Thread.Sleep(this.Frequency);
    34.             }
    35.         });
    36.  
    37.         thread.Start();
    38.     }
    39. #endif
    40. }
    It has one big issue however. Because you callbacks now called from a thread other than Unity's main thread, you might have to deal with thread synchronization and a lot of Unity functions can be called from their main thread only!
     
  22. MarieScala

    MarieScala

    Joined:
    Dec 5, 2017
    Posts:
    16
    Hi ! Maybe a silly question but I saw the demo and the download texture example, then I quick read some questions here, and everybody seems to need to download things from their server. I need to upload screenshots, png format, with a POST request ( I think ). I'm totally beginner in web stuff, will this plugin do the trick ? Is it possible to upload png format as well as simple txt format ?

    Thanks in Advance !
     
  23. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @MarieScala

    Yes, it can upload too with POST, PUT, etc. For example, you can upload a png like this:
    Code (CSharp):
    1. Uri uri = new Uri("http://httpbin.org/post");
    2.  
    3. HTTPRequest request = new HTTPRequest(uri, HTTPMethods.Post, (req, resp) =>
    4. {
    5.     switch (req.State)
    6.     {
    7.         // The request finished without any problem.
    8.         case HTTPRequestStates.Finished:
    9.             if (resp.IsSuccess)
    10.             {
    11.                 Debug.Log("Request Finished Successfully! Response: " + resp.DataAsText);
    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.                                                 resp.StatusCode,
    16.                                                 resp.Message,
    17.                                                 resp.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. });
    41.  
    42. request.AddBinaryData("myfile", this.tex.EncodeToPNG());
    43.  
    44. request.Send();
     
  24. MarieScala

    MarieScala

    Joined:
    Dec 5, 2017
    Posts:
    16
    Wow, that was a quick and clear answer. Awesome ! ._.
     
    Cromfeli likes this.
  25. davewx7

    davewx7

    Joined:
    Feb 25, 2018
    Posts:
    2
    @BestHTTP: Sorry for the delay in responding (re: server sent events working with WebGL).

    I don't see much interesting in the browser developer console log. I logged a message to confirm creating an EventSource, and setting listeners on OnClosed / OnError / OnMessage. Then I just get the following log messages:

    1 ES_Create(https://my-url.com/etc/etc, 0)
    1 ES_Create - onOpen

    There are no other log messages, and my OnClosed / OnError / OnMessage listeners never get called.

    This is when using Firebase -- doing https://firebase.google.com/docs/database/rest/retrieve-data the "Streaming from the REST API" section. I wonder if you have tried that particular use case yourself?

    It works perfectly in the Unity editor and on iOS and Android clients.

    Thanks in advance for any help or insights!
     
  26. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @davewx7

    Under webgl the plugin uses the browser's EventSource implementation. The plugin logs out messages from the EventSource implementation for the generic onmessage (this present in the browser console as something like '1 on Generic Message') and subscription based events ('1 onEvent('+ eventName + ')').
    How are you using the plugin's EventSource class? Are you using the generic OnMessage event or are you using the On function to subscribe to specific events? If the later, the console have to contain an entry with the ES_AddEventHandler string too.

    My knowledge about firebase is shallow, didn't tried their eventsource api. Is it possible to send a repro-project over, so i could test it myself?
     
  27. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    54
    Hi, in the docs you say to not use BeginCacheMaintenance if there are any requests being processed. Is there an easy way to make sure of that? RequestQueue is private.
    Also what would happen in case a request was being processed, receiving a 304 but the cached entry was gone? error? request is resent?

    Thanks!
     
  28. BestHTTP

    BestHTTP

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

    The only problem calling BeginClear or BeginMaintainence the one that you already asked. If the cached entry is removed after the plugin is sent out a request based on its existence and the server returns that it's fresh enough to load from the client's local storage. In this case the request will be in an errored state when its callback is called.

    You should call these function somewhere in your startup code before any request sending.
     
  29. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    54
    Does it happen on the main thread or is it asynchronous? I have some calls happening very early on startup, is it safe to do the cache maintenance as long as it's called before any requests?
     
  30. BestHTTP

    BestHTTP

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

    They are asynchronous. You can add a property like this to the HTTPCacheService class to check whether a maintenance is running or not:
    Code (CSharp):
    1. public static bool IsDoingMaintainence { get { return InClearThread || InMaintainenceThread; } }
    Then you can wait in a coroutine while it's true. This would be the safest way.
     
    Numa likes this.
  31. dev_runeofdark

    dev_runeofdark

    Joined:
    Oct 27, 2016
    Posts:
    10
    Hi

    I have little question about the HTTPRequest class: If I make a request to a webservice is it possible to do this asynchronous or Unity doesn't allow this because you make use of unity objects?
     
  32. BestHTTP

    BestHTTP

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

    The plugin always processes the request asynchronously, only the callback are called from Unity's main thread.
     
  33. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    54
    Hello again! Thanks for the great support!
    Would it be possible for you to add a user agent variable to the httpManager to allow setting a default value for all requests? Have done this myself but it would be a good addition to the package :)

    Thanks
     
  34. BestHTTP

    BestHTTP

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

    That's a great idea!
     
    Numa likes this.
  35. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    54
    Awesome, I'll be watching your updates :D Is there a place where I should go to be alerted of updates to the plugin?
     
  36. netics

    netics

    Joined:
    Aug 23, 2011
    Posts:
    102
    Hello, BestHttps.

    I tried to upgrade latest version(1.11.0) and got compile error messages below.
    I already tried
    1. delete old assets and re-install.
    2. open ReleaseNote.txt file and check that the version is 1.11.0
    3. delete unity asset store cache and re-download.

    What should I do?

    ---------------------------------------------------------------
    Assets/Standard Assets/Best HTTP (Pro)/BestHTTP/SignalRCore/Authentication/DefaultAccessTokenAuthenticator.cs(5,59): error CS0246: The type or namespace name `IAuthenticationProvider' could not be found. Are you missing an assembly reference?
    Assets/Standard Assets/Best HTTP (Pro)/BestHTTP/SignalRCore/Authentication/DefaultAccessTokenAuthenticator.cs(16,22): error CS0246: The type or namespace name `OnAuthenticationSuccededDelegate' could not be found. Are you missing an assembly reference?
    Assets/Standard Assets/Best HTTP (Pro)/BestHTTP/SignalRCore/Authentication/DefaultAccessTokenAuthenticator.cs(21,22): error CS0246: The type or namespace name `OnAuthenticationFailedDelegate' could not be found. Are you missing an assembly reference?
    Assets/Standard Assets/Best HTTP (Pro)/BestHTTP/SignalRCore/Authentication/DefaultAccessTokenAuthenticator.cs(25,17): error CS0246: The type or namespace name `HubConnection' could not be found. Are you missing an assembly reference?
    Assets/Standard Assets/Best HTTP (Pro)/BestHTTP/SignalRCore/Authentication/DefaultAccessTokenAuthenticator.cs(27,48): error CS0246: The type or namespace name `HubConnection' could not be found. Are you missing an assembly reference?
    Assets/Standard Assets/Best HTTP (Pro)/BestHTTP/SignalRCore/Messages/NegotiationResult.cs(51,80): error CS0246: The type or namespace name `HubConnection' could not be found. Are you missing an assembly reference?
    -------------------------------------------------------------------
     
  37. BestHTTP

    BestHTTP

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

    You should receive recent plugin updates to your email account that you used for purchase by the Unity Asset Store.
     
    Numa likes this.
  38. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @netics

    There's a pending update in the asset store that should fix this issue, but sent a download link in a private message.
     
  39. netics

    netics

    Joined:
    Aug 23, 2011
    Posts:
    102
    It works. Thanks!
     
  40. netpenthe1

    netpenthe1

    Joined:
    Jan 20, 2017
    Posts:
    2
    + for kerberos - pleeeeease (happy to pay a bounty?)
     
  41. HaakonL

    HaakonL

    Joined:
    Mar 13, 2014
    Posts:
    116
    Does it have HTTP/2 support?
     
  42. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @HaakonL

    No. What feature(s) of HTTP/2 are you interested in the most?
     
  43. chris_jimison

    chris_jimison

    Joined:
    Jan 17, 2019
    Posts:
    2
    Hi BestHTTP,

    I seem to be having a bit of an issue when using BestHTTP websocket to connect with a Rust Server built on top of actix_web (don't worry, this is not an actix_web or Rust question :p ). My issue to come down to how closely folks read RFC 7230 section-3.3.2. Specifically this part:

    "A user agent SHOULD NOT send a Content-Length header field when the request message does not contain a payload body and the method semantics do not anticipate such a body."

    "SHOULD NOT" is a bit too ambiguous IMO, and the actix_web folks took it to mean "MUST NOT". As such every time I try to open up a BestHTTP websocket to the server, it will close it via a TCP RST. I did a bit of hacking in the codebase and I modified HTTPRequest.cs line 952 like so:

    Code (CSharp):
    1. //#if !UNITY_WEBGL || UNITY_EDITOR
    2. //                contentLength >= 0
    3. //#else
    4. //                contentLength != -1
    5. //                contentLength > 0
    6. //#endif
    7.                 contentLength > 0
    With this change I can connect/run the sample to both echo.websocket.org as well as my server. Any thoughts/concerns here?

    Thanks!
     
  44. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @chris_jimison

    Yeah, different implementations are enforcing different rules. There are servers out there that require the content-length header even if there's no content body... (And not to speak about the http/1.0 servers that also require it.)

    You will be fine with your change.
     
  45. chris_jimison

    chris_jimison

    Joined:
    Jan 17, 2019
    Posts:
    2
    Any thoughts on making this a compiler option that can be set for servers like mine? I can't believe I would be the only one who hits this issue and it was hell of hard to figure out :).
     
  46. rreynoldsea

    rreynoldsea

    Joined:
    Apr 8, 2019
    Posts:
    2
    Hello fellow Unity friends and lovers of BestHTTP. I was hoping someone out there might have some success using Spring Boot Websockets with BestHTTP websockets? I created a simple endpoint following the docs:

    Spring Boot Rest Controller ( java )
    Code (CSharp):
    1. @RestController
    2. @RequestMapping("events/v1")
    3. @RequiredArgsConstructor
    4. public class EventsApi {
    5.  
    6.     // Domain
    7.     private final EventsApplicationService eventsApplicationService;
    8.  
    9.     @GetMapping(path = "/listen")
    10.     public Flux<ServerSentEvent<String>> listen() {
    11.         return eventsApplicationService.listen()
    12.                 .map(stringServerSentEvent -> ServerSentEvent.<String>builder()
    13.                         .id(String.valueOf(stringServerSentEvent.hashCode()))
    14.                         .event("event-update")
    15.                         .data(stringServerSentEvent).build());
    16.     }
    17.  
    18. }
    Spring Boot Service Class ( java )

    Code (CSharp):
    1. @Service
    2. @AllArgsConstructor
    3. public class EventsApplicationService {
    4.  
    5.     public void addEvent(String personaId, Map<String, String> events) {
    6.  
    7.     }
    8.  
    9.     public Flux<String> listen() {
    10.         return Flux.interval(Duration.ofSeconds(1))
    11.                 .map(sequence -> String.format("Event #%s", sequence));
    12.     }
    13.  
    14. }
    On the client I have something like the following that starts on boot:

    Code (CSharp):
    1.             _webSocket = new WebSocket(new Uri("http://localhost:8080/events/v1/listen"))
    2.             {
    3.                 StartPingThread = true
    4.             };
    5.             // Subscribe to the WS events
    6.             _webSocket.OnOpen += OnOpen;
    7.             _webSocket.OnMessage += OnMessageReceived;
    8.             _webSocket.OnClosed += OnClosed;
    9.             _webSocket.OnError += OnError;
    10.  
    11.             // Start connecting to the server
    12.             _webSocket.Open();
    Unfortunately it seems to timeout and hit the error callback sometime later with an obscure message that doesn't seem to be relevant to whatever caused the problem.
     
  47. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @chris_jimison

    It can be some kind of option, but you are the first to hit an issue with this specific case. But, I will think about it.
     
  48. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @rreynoldsea

    Is it possible to send me an url in private that I could use to test? Also I would like to know what was the obscure message, it might still contain some information.
     
    Last edited: Apr 9, 2019
  49. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    84
    Hello,

    I want to add a Server function to my Unity app, it should send the main camera screen. Maybe as a Byte Array from screenshot.

    I want to have a platform Independent Client, that can watch the Video stream. And the client should be able to send strings or something, just to Control the camera with mouse and Cursor keys or something like that.

    I already bought your asset for something else, but can I use it for this context? What of the supported modes would you recomment to use?

    Websocket? Html? Or even SignalR?

    Thanks :)
     
  50. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,455
    @LR-Developer

    I think your best option would be to use websockets. It allows you to send/receive binary data too, without any additional transformation. This applies to the control data you want to send too.
    It's more work to implement, but because your main data is binary, it will be the most efficient too!
     
    LR-Developer likes this.
unityunity