Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Best HTTP Released

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

  1. Zinios

    Zinios

    Joined:
    Nov 7, 2017
    Posts:
    5
    @BestHTTP i am getting this error in few windows system can you tell why this happens??

    Code: Internal Message: "Socket Exception
    at BestHTTP.PlatformSupport.TcpClient.WinRT.TcpClient.Connect(String hostName, Int32 port)
    at BestHTTP.HTTPConnection.Connect()
    at BestHTTP.HTTPConnection.<ThreadFunc>d__6.MoveNext()"
     
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @Zinios

    Socket Exception is thrown when the DNS couldn't resolve the IP address of the host, or if it can't connect to it.
     
  3. Zinios

    Zinios

    Joined:
    Nov 7, 2017
    Posts:
    5
    @BestHTTP it happens only in few system what can be the reason
     
  4. grimcat

    grimcat

    Joined:
    Jul 12, 2013
    Posts:
    34
    I'm looking at the documentation, but don't see examples on using SignalR Core. I'm assuming that I'm supposed to use the HubConnection class, but I can't figure out what argument to pass to the protocol
     
  5. grimcat

    grimcat

    Joined:
    Jul 12, 2013
    Posts:
    34
    This seems to be the only option at the moment as the other encoders are not implemented:

    Code (CSharp):
    1. using BestHTTP.SignalRCore;
    2. using BestHTTP.SignalRCore.Encoders;
    3.  
    4. HubConnection hubConnection = new HubConnection(uri, new JsonProtocol(new LitJsonEncoder()));
    5.  
    6. hubConnection.StartConnect();
    Does that look correct?
     
  6. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @Zinios

    They can happen if there's connectivity issues on the client machine.
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
  8. turdann

    turdann

    Joined:
    Dec 29, 2012
    Posts:
    43
    Hello,

    I'm trying implementing a socket using BestHTTP.
    I'm having an issue testing disconnections on PC. After pulling the ethernet cord, it takes the socket almost 30 seconds to detect a disconnection.
    I've set the Timeout in options to 1, just for testing.

    Any way to lower the overall waiting time until a disconnection is detected?
     
    Last edited: Aug 2, 2019
  9. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @turdann

    Without traffic the tcp protocol can't detect disconnectivity. The TCP protocol has an optional keep-alive extension (https://tools.ietf.org/html/rfc1122#page-101) and even if it's implemented it must be off by default. I have tried to turn it on but i received different results depending on the running platform sometime making it worse.
    You can find my code in \Best HTTP (Pro)\BestHTTP\PlatformSupport\TcpClient\TcpClient.cs' Connect function around line 485.
    No wonder why every higher level protocols (WebSockets, Socket.IO, SignalR and SignalR Core) implement their ping-pong mechanisms to detect broken connections.
     
  10. turdann

    turdann

    Joined:
    Dec 29, 2012
    Posts:
    43
    So it would be better to implement our own ping-pong mechanism to detect a disconnection instead of relaying on the default one, right?

    Also, on the socket example you provide, the chat one, there's a lot of logging involved. How can I show all that log info in my project?

    Thanks!
     
  11. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @turdann

    If socket in your case means Socket.IO than you should use Socket.IO's own ping mechanism.

    You can turn on detailed logging like this somewhere in your startup code:
    Code (CSharp):
    1. BestHTTP.HTTPManager.Logger.Level = BestHTTP.Logger.Loglevels.All;
     
  12. turdann

    turdann

    Joined:
    Dec 29, 2012
    Posts:
    43
    Great, thanks. I'll look into it.
     
  13. LTPStudioXR

    LTPStudioXR

    Joined:
    Nov 1, 2016
    Posts:
    11
    I'm working in 2019.2 Since Unity Networking has been deprecated I'm wondering if I can use BestHTTP to identify my IP address. I'm interesting in getting local weather data for my area.
     
  14. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
  15. GordonWedge

    GordonWedge

    Joined:
    Jul 6, 2013
    Posts:
    23
    Hello,
    i'm using this great package since 2 years and it worked flawless.
    Now i've got a problem, i have to download a big file from an url, and i always used this code:

    Code (CSharp):
    1.  
    2. request = new HTTPRequest(new Uri(UrlFile), (req, resp) =>
    3. .....
    and managed request with state and fragments.
    Now i've to send a token with my request to be allowed to download the file, i've got the token with another function, how can i send it with my request?

    i've tryed this code:

    Code (CSharp):
    1. request.SetHeader("Authorization", "Bearer "+token);
    but it doesn't works.
     
  16. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @GordonWedge

    Well, that depends on where and how your server expects it. Is there a documentation about the server side, or can you show its code?
     
  17. GordonWedge

    GordonWedge

    Joined:
    Jul 6, 2013
    Posts:
    23
    Hi, server side we have a node js app, it expects a bearer token, here is an example code generated from postman:

    Code (CSharp):
    1.  
    2. var client = new RestClient("http://myserverip:3000/api/folder/package.7z");
    3. var request = new RestRequest(Method.GET);
    4. request.AddHeader("cache-control", "no-cache");
    5. request.AddHeader("Connection", "keep-alive");
    6. request.AddHeader("Accept-Encoding", "gzip, deflate");
    7. request.AddHeader("Host", "myserverip:3000");
    8. request.AddHeader("Postman-Token", "7990b412-b89d-4cce-9277-623961d0a347,e527e37b-0cd8-4c7d-aba3-d6fbe1a0d480");
    9. request.AddHeader("Cache-Control", "no-cache");
    10. request.AddHeader("Accept", "*/*");
    11. request.AddHeader("User-Agent", "PostmanRuntime/7.15.2");
    12. request.AddHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7Il9pZCI6Mn0sImlhdCI6MTU2NDk5Mjc0NSwiZXhwIjoxNTY1MDI4NzQ1fQ.E8iy5jz7g-sijyiaEXAU2AVKJUGo9klVO6IjKzdyZHA");
    13. IRestResponse response = client.Execute(request);
     
  18. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @GordonWedge

    That must work with the plugin too. Could you capture the communication between your app and your server with Charles Proxy?
    You can setup the plugin to use the proxy by calling this line somewhere in your startup code:
    Code (CSharp):
    1. HTTPManager.Proxy = new HTTPProxy(new Uri("http://localhost:8888"), null, true);
    Then you can save and send the captured communication to my mail address (besthttp@gmail.com).
     
  19. Zapan15

    Zapan15

    Joined:
    Apr 11, 2011
    Posts:
    186
    We have a Problem with unity 2019.2.0f1 and the newest BestHTTP Pro when uploading a file.

    When uploading, it starts at HTTPResponse.ReadTo the ReadByte method in ReadOnlyBufferedStream get an exception: "
    Could not read from buffer:Unable to read data from the transport connection: Ein Blockierungsvorgang wurde durch einen Aufruf von WSACancelBlockingCall unterbrochen.". The upload command will be never finished and ends up in an endless loop.

    The issue is new, and was not there in 2019.1.XX Version of Unity.
     
  20. Zapan15

    Zapan15

    Joined:
    Apr 11, 2011
    Posts:
    186
    It looks like that the stream.ReadByte() in HTTPResponse (line 483) never finishes...
     
  21. Zapan15

    Zapan15

    Joined:
    Apr 11, 2011
    Posts:
    186
  22. Zapan15

    Zapan15

    Joined:
    Apr 11, 2011
    Posts:
    186
    After further investigation I can say, that this is also happening with older Versions of Unity. It looks also that the socket has `(stream as System.Net.Sockets.NetworkStream).DataAvailable == false`, which end up, that we cannot read from the socket.

    Other commands like downloading etc. are working fine, and they have `DataAvailable == true`
     
  23. Zapan15

    Zapan15

    Joined:
    Apr 11, 2011
    Posts:
    186
    Sorry for spamming the forum. However, we found the issue. It has nothing todo with your Component! Everything works as expected! :cool:
     
  24. Fatih86

    Fatih86

    Joined:
    Mar 3, 2014
    Posts:
    7
    Hey,

    I have actualized my node.js version to latest (v12.8.0) and enabled the websocket transport in server.

    Code (CSharp):
    1. var io = require('socket.io')(server, {'transports': ['websocket', 'polling']});
    Now I get another Error

    Code (CSharp):
    1. Code: Internal Message: "Request Finished Successfully, but the server sent an error. Status Code: 400-Bad Request Message: {"code":3,"message":"Bad request"}"
    2. 0x00007FF66729818C (Unity) StackWalker::GetCurrentCallstack
    3. 0x00007FF66729B641 (Unity) StackWalker::ShowCallstack
    4. 0x00007FF6659FAFF5 (Unity) GetStacktrace
    5. 0x00007FF667CBDE20 (Unity) DebugStringToFile
    6. 0x00007FF6672C6E69 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    7. 0x000001E01C3DF6AB (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    8. 0x000001E01C3DF2EB (Mono JIT Code) [DebugLogHandler.cs:10] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    9. 0x000001E01C3DE981 (Mono JIT Code) [Logger.cs:61] UnityEngine.Logger:Log (UnityEngine.LogType,object)
    10. 0x000001E01C3DE5E0 (Mono JIT Code) [Debug.bindings.cs:99] UnityEngine.Debug:Log (object)
    11. 0x000001E01E8EF9BB (Mono JIT Code) [NetworkManager.cs:371] NetworkManager:OnError (BestHTTP.SocketIO.Socket,BestHTTP.SocketIO.Packet,object[])
    12. 0x000001E01E8EED86 (Mono JIT Code) [EventDescriptor.cs:74] BestHTTP.SocketIO.Events.EventDescriptor:Call (BestHTTP.SocketIO.Socket,BestHTTP.SocketIO.Packet,object[])
    13. 0x000001E01CA20313 (Mono JIT Code) [EventTable.cs:84] BestHTTP.SocketIO.Events.EventTable:Call (string,BestHTTP.SocketIO.Packet,object[])
    14. 0x000001E01CA1FCE3 (Mono JIT Code) [Socket.cs:448] BestHTTP.SocketIO.Socket:BestHTTP.SocketIO.ISocket.EmitEvent (string,object[])
    15. 0x000001E01CA1F84A (Mono JIT Code) [SocketManager.cs:562] BestHTTP.SocketIO.SocketManager:BestHTTP.SocketIO.IManager.EmitEvent (string,object[])
    16. 0x000001E01E8EE8EC (Mono JIT Code) [SocketManager.cs:570] BestHTTP.SocketIO.SocketManager:BestHTTP.SocketIO.IManager.EmitEvent (BestHTTP.SocketIO.SocketIOEventTypes,object[])
    17. 0x000001E01E8EE50D (Mono JIT Code) [SocketManager.cs:575] BestHTTP.SocketIO.SocketManager:BestHTTP.SocketIO.IManager.EmitError (BestHTTP.SocketIO.SocketIOErrors,string)
    18. 0x000001E01E8EE2DA (Mono JIT Code) [SocketManager.cs:427] BestHTTP.SocketIO.SocketManager:BestHTTP.SocketIO.IManager.OnTransportError (BestHTTP.SocketIO.Transports.ITransport,string)
    19. 0x000001E01E8EE055 (Mono JIT Code) [WebSocketTransport.cs:245] BestHTTP.SocketIO.Transports.WebSocketTransport:OnError (BestHTTP.WebSocket.WebSocket,System.Exception)
    20. 0x000001E01E8EC8CB (Mono JIT Code) [WebSocket.cs:344] BestHTTP.WebSocket.WebSocket:OnInternalRequestCallback (BestHTTP.HTTPRequest,BestHTTP.HTTPResponse)
    21. 0x000001E01E8EBD60 (Mono JIT Code) [HTTPRequest.cs:1311] BestHTTP.HTTPRequest:CallCallback ()
    22. 0x000001E01E8EBA2B (Mono JIT Code) [ConnectionBase.cs:161] BestHTTP.ConnectionBase:HandleCallback ()
    23. 0x000001E01CA7B903 (Mono JIT Code) [HTTPManager.cs:622] BestHTTP.HTTPManager:OnUpdate ()
    24. 0x000001E01CA78DE3 (Mono JIT Code) [HTTPUpdateDelegator.cs:178] BestHTTP.HTTPUpdateDelegator:Update ()
    25. 0x000001E01C9A05A8 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    26. 0x00007FFA517FB6B0 (mono-2.0-bdwgc) [mini-runtime.c:2809] mono_jit_runtime_invoke
    27. 0x00007FFA51781D12 (mono-2.0-bdwgc) [object.c:2919] do_runtime_invoke
    28. 0x00007FFA5178AD0F (mono-2.0-bdwgc) [object.c:2966] mono_runtime_invoke
    29. 0x00007FF66722A0B6 (Unity) scripting_method_invoke
    30. 0x00007FF6672243A5 (Unity) ScriptingInvocation::Invoke
    31. 0x00007FF6671E0A82 (Unity) MonoBehaviour::CallMethodIfAvailable
    32. 0x00007FF6671E0E26 (Unity) MonoBehaviour::CallUpdateMethod
    33. 0x00007FF666905B44 (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
    34. 0x00007FF66690E144 (Unity) BehaviourManager::Update
    35. 0x00007FF666D3F643 (Unity) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward
    36. 0x00007FF666D28B58 (Unity) ExecutePlayerLoop
    37. 0x00007FF666D28C36 (Unity) ExecutePlayerLoop
    38. 0x00007FF666D2D7F0 (Unity) PlayerLoop
    39. 0x00007FF665A48CA0 (Unity) PlayerLoopController::UpdateScene
    40. 0x00007FF665A45D28 (Unity) Application::TickTimer
    41. 0x00007FF665D043EB (Unity) MainMessageLoop
    42. 0x00007FF665D0DDF7 (Unity) WinMain
    43. 0x00007FF66865653E (Unity) __scrt_common_main_seh
    44. 0x00007FFAD39D7974 (KERNEL32) BaseThreadInitThunk
    45. 0x00007FFAD604A271 (ntdll) RtlUserThreadStart
    Any hints?

    br
     
    Last edited: Aug 7, 2019
  25. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @Fatih86

    I guess you are using the latest socket.io. You can set the plugin's log level to verbose and send the complete log to me(besthttp@gmail.com):
    Code (CSharp):
    1. HTTPManager.Logger.Level = Logger.Loglevels.All;
    Seeing the logs maybe I will know more about what went wrong.
     
  26. tranpd

    tranpd

    Joined:
    Aug 12, 2016
    Posts:
    13
    @BestHTTP I have a problem, i use Get Requests, but always return response.StatusCode = 304 and response.DataAsText has nothing wrong, i am using Unity 2019.2
    Code (CSharp):
    1.   HTTPRequest request = new HTTPRequest(new Uri("https://myUrl.api.net"), HTTPMethods.Get, (request, response) =>{
    2.            Debug.Log(response.StatusCode);
    3.            Debug.Log(response.DataAsText);
    4.         });
    5. request.Send();
    6.  
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @tranpd

    Status code 304 is an expected one if the content downloaded from the local cache.
     
  28. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    Hello,

    I Need to create a WPF App which has some WPF ui and viewmodels and has a handle in which my Unity App is running and Shows some 3d stuff.

    Now I Need to send some Events and some data from my WPF App to the Unity app which is started as a process.
    Both Need to communicate. Can I use Best HTTP for this communication? Could you reccoment the best Technology for this, Maybe it can be done best with SignalR?

    I have already purchased Best HTTP but didn't use it yet.

    Thanks a lot!
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    LR-Developer likes this.
  30. BernEugen

    BernEugen

    Joined:
    Mar 13, 2015
    Posts:
    4
    Hello dear BestHTTP developer.
    Is there a possibility in the library to make multiple HTTPRequests on different urls but to receive only one callback when all results are ready and sent to me back? And the results would be sorted, that I would know for which request belongs each result.
    Thank you.
     
    Last edited: Aug 15, 2019
  31. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @BernEugen

    No, not out of the box, but with one or two helper functions it can be implemented on top of the plugin.
     
    BernEugen likes this.
  32. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    Hello,

    I found what seems to be a bug using Socketio.

    I need all my data to be encoded with "types". So my json-encoder is setup to `TypeNameHandling = TypeNameHandling.All`

    But line 181 of the Socket.cs file, BestHTTP is actually serializing everything with the serializer. So the payload is messed up.

    Basically I'm getting :

    Code (JavaScript):
    1. {"$type":"System.Collections.Generic.List`1[[System.Object, mscorlib]], mscorlib","$values":["Users.auth",{"$type":"LoneStoneStudio.CityInvaders.LoginDTO, CityInvaders.Runtime","email":"user_1@user.fr","password":"password"}]}
    Instead of

    Code (CSharp):
    1. ["Users.auth",{"$type":"LoneStoneStudio.CityInvaders.LoginDTO, CityInvaders.Runtime","email":"user_1@user.fr","password":"password"}]
     
    Last edited: Aug 20, 2019
  33. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @RDeluxe

    That's because the socket.io protocol expects an emit call as a json list. The first element is the event name and all the other elements in the list going to be the arguments of the event. So the plugin puts all of them into a list to encode with the encoder.
     
  34. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    Hello,
    I do not get my SignalRCore communication working.
    I just want a local communication between a WPF app and my Unity app.
    First I tried with Localhost, then with some Code to get my local IP, which seems to work and I can ping.
    The Code is from the SignalRCore hub sample, the WPF Code is something I found on the net...
    Code (CSharp):
    1.     void Start()
    2.     {
    3.         // Server side of this example can be found here:
    4.         // https://github.com/Benedicht/BestHTTP_DemoSite/blob/master/BestHTTP_DemoSite/Hubs/TestHub.cs
    5.         // Set up optional options
    6.         HubOptions options = new HubOptions();
    7.         options.SkipNegotiation = false;
    8.         URI = new Uri("http://" + GetLocalIPAddress() + ":" + port);
    9.         // Crete the HubConnection
    10.         hub = new HubConnection(URI, new JsonProtocol(new LitJsonEncoder()), options);
    11.         // Optionally add an authenticator
    12.         //hub.AuthenticationProvider = new BestHTTP.SignalRCore.Authentication.HeaderAuthenticator("<generated jwt token goes here>");
    13.         // Subscribe to hub events
    14.         hub.OnConnected += Hub_OnConnected;
    15.         hub.OnError += Hub_OnError;
    16.         hub.OnClosed += Hub_OnClosed;
    17.         hub.OnMessage += Hub_OnMessage;
    18.         // Set up server callable functions
    19.         hub.On("Send", (string arg) => uiText += string.Format(" On Send: {0}\n", arg));
    20.         // And finally start to connect to the server
    21.         hub.StartConnect();
    22.         uiText = "StartConnect called\n";
    23.     }
    24.     public static string GetLocalIPAddress()
    25.     {
    26.         var host = Dns.GetHostEntry(Dns.GetHostName());
    27.         foreach (var ip in host.AddressList)
    28.         {
    29.             if (ip.AddressFamily == AddressFamily.InterNetwork)
    30.             {
    31.                 return ip.ToString();
    32.             }
    33.         }
    34.         throw new Exception("Local IP Address Not Found!");
    35.     }
    I started it as an Admin, but when I try to get a Connection, I only get a negotiation error (in german, it means the target Computer says it is not allowed):
    "Negotiation Request Finished with Error! Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte.\r\n\n at BestHTTP.PlatformSupport.TcpClient.General.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, System.Int32 port) [0x00123] in C:\\Unity\\DigTwin\\Assets\\Best HTTP (Pro)\\BestHTTP\\PlatformSupport\\TcpClient\\TcpClient.cs:522 \r\n at BestHTTP.PlatformSupport.TcpClient.General.TcpClient.Connect (System.String hostname, System.Int32 port) [0x0005e] in C:\\Unity\\DigTwin\\Assets\\Best HTTP (Pro)\\BestHTTP\\PlatformSupport\\TcpClient\\TcpClient.cs:418 \r\n at BestHTTP.HTTPConnection.Connect () [0x00173] in C:\\Unity\\DigTwin\\Assets\\Best HTTP (Pro)\\BestHTTP\\HTTPConnection.cs:465 \r\n at BestHTTP.HTTPConnection.ThreadFunc () [0x00063] in C:\\Unity\\DigTwin\\Assets\\Best HTTP (Pro)\\BestHTTP\\HTTPConnection.cs:169 "

    Any idea what am I doing wrong? I also told the Firewall the apps are both allowed, but it seems to be something else, but I am unsure…

    thanks a lot
     
  35. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    PS: I tried Localhost, 127.0.01, add to make a port known like that:

    netsh http add urlacl url=http://+:50014/ user=Domain\user

    but Nothing seems to help, always the same Problem when connecting. Any idea? Thanks!
     
  36. BestHTTP

    BestHTTP

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

    Are you sure you are trying to connect to the proper port? If you host your server on localhost you shouldn't have to add any firewall rule.
     
  37. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    Hello,

    I tried to get a free port like this:

    Code (CSharp):
    1.     //static int FreeTcpPort()
    2.     //{
    3.     //    TcpListener l = new TcpListener(IPAddress.Loopback, 0);
    4.     //    l.Start();
    5.     //    int port = ((IPEndPoint)l.LocalEndpoint).Port;
    6.     //    l.Stop();
    7.     //    return port;
    8.     //}
    9.  
    10.     static int FreeTcpPort()
    11.     {
    12.         IPEndPoint endPoint;
    13.         int port = 1;
    14.         while (true)
    15.         {
    16.             try
    17.             {
    18.                 endPoint = new IPEndPoint(IPAddress.Any, port);
    19.                 break;
    20.             }
    21.             catch (SocketException)
    22.             {
    23.                 port++;
    24.             }
    25.         }
    26.         return port;
    27.     }
    Both gave me something > 50000.

    URI = new Uri("http://" + GetLocalIPAddress() + ":" + FreeTcpPort());

    I still get the Error Message from above, that the target Computer refuses.
    The error message is not after 15 seconds, it is very fast...

    Thanks for helping.
     
  38. BestHTTP

    BestHTTP

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

    You have to find what port is your server bound to and connect to that port. So, for example if your server is running on port 3000, you can use the url "http://localhost:3000".
     
  39. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    The WPF App is the other side. I tried to bind both to port 55016 now which should be free and working.

    I added a while loop now because I thought they might not find each other soon enough.

    Both are started on the same PC. This is my WPF App Code:

    Code (CSharp):
    1.     Uri URI = new Uri("http://localhost");
    2.  
    3.     HubConnection connection;
    4.     public SignalRCoreHelper()
    5.     {
    6.         URI = new Uri("http://" + GetLocalIPAddress() + ":" + FreeTcpPort());
    7.  
    8.         connection = new HubConnectionBuilder()
    9.         .WithUrl(URI)
    10.         .Build();      
    11.         connection.Closed += async (error) =>
    12.         {
    13.             await Task.Delay(new Random().Next(0, 5) * 1000);
    14.             connection.ServerTimeout = TimeSpan.FromSeconds(15);
    15.             connection.HandshakeTimeout = TimeSpan.FromSeconds(15);
    16.             await connection.StartAsync();
    17.         };
    18.     }
    19.  
    20.     public static string GetLocalIPAddress()
    21.     {
    22.         var host = Dns.GetHostEntry(Dns.GetHostName());
    23.         foreach (var ip in host.AddressList)
    24.         {
    25.             if (ip.AddressFamily == AddressFamily.InterNetwork)
    26.             {
    27.                 return ip.ToString();
    28.             }
    29.         }
    30.         throw new Exception("Local IP Address Not Found!");
    31.     }
    32.  
    33.     static int FreeTcpPort()
    34.     {
    35.         //TcpListener l = new TcpListener(IPAddress.Loopback, 0);
    36.         //l.Start();
    37.         //int port = ((IPEndPoint)l.LocalEndpoint).Port;
    38.         //l.Stop();
    39.         //return port;
    40.         return 55016;
    41.     }
    42.  
    43.     public async void Connect()
    44.     {
    45.         connection.On<string, string>("ReceiveMessage", (user, message) =>
    46.         {
    47.             Application.Current.Dispatcher.Invoke(() =>
    48.             {
    49.                 var newMessage = $"{user}: {message}";
    50.             });
    51.         });
    52.         int tries = 0;
    53.         while (connection.State == HubConnectionState.Disconnected && tries < 1000)
    54.         {
    55.             try
    56.             {
    57.                 await connection.StartAsync();
    58.             }
    59.             catch (Exception ex)
    60.             {
    61.                 Debug.Write(ex.Message);
    62.             }
    63.             Task.Delay(100);
    64.             tries++;
    65.         }
    66.     }
    67.  
    Thanks a lot!
     
  40. BestHTTP

    BestHTTP

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

    Could you pack both of those projects and send it to me?
     
  41. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    I can try, I will have to remove a lot of stuff then…

    Can you confirm for the WPF App that runs the SignalR Core Server and "talks" to the SignalR Core Client using BestHTTP this is the correct library and Version?
    upload_2019-8-28_8-45-14.png

    Thanks!
     
  42. BestHTTP

    BestHTTP

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

    I'm sorry but I'm not familiar with the libraries, I usually use their github repo. Anyway, even if you use the wrong package it would connect if the port is open and would throw a different error later.
     
  43. Jochanan

    Jochanan

    Joined:
    Nov 9, 2016
    Posts:
    85
    Hi, do you have any idea, what may be the cause of this error?
    Code (CSharp):
    1. Request Finished with Error! Attempted to Seek before the beginning of the stream
    2.   at System.IO.FileStream.Seek (System.Int64 offset, System.IO.SeekOrigin origin) [0x0006e] in <1f0c1ef1ad524c38bbc5536809c46b48>:0
    3.   at BestHTTP.Caching.HTTPCacheFileInfo.GetBodyStream (System.Int32& length) [0x0003c] in C:\Users\BGLab\Documents\Projekty\client\Assets\Plugins\Best HTTP (Pro)\BestHTTP\Caching\HTTPCacheFileInfo.cs:309
    4.   at BestHTTP.HTTPConnection.LoadFromCache (System.Uri uri) [0x0009c] in C:\Users\BGLab\Documents\Projekty\client\Assets\Plugins\Best HTTP (Pro)\BestHTTP\HTTPConnection.cs:613
    5.   at BestHTTP.HTTPConnection.Receive () [0x00178] in C:\Users\BGLab\Documents\Projekty\client\Assets\Plugins\Best HTTP (Pro)\BestHTTP\HTTPConnection.cs:580
    6.   at BestHTTP.HTTPConnection.ThreadFunc () [0x0013b] in C:\Users\BGLab\Documents\Projekty\client\Assets\Plugins\Best HTTP (Pro)\BestHTTP\HTTPConnection.cs:213
    7. UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    8. UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    9. UnityEngine.Logger:Log(LogType, Object)
    10. UnityEngine.Debug:LogError(Object)
    11. TextureLoader:RequestFinished(HTTPRequest, HTTPResponse) (at Assets\Scripts\GlobalManagers\TextureLoader.cs:78)
    12. BestHTTP.HTTPRequest:CallCallback() (at Assets\Plugins\Best HTTP (Pro)\BestHTTP\HTTPRequest.cs:1311)
    13. BestHTTP.ConnectionBase:HandleCallback() (at Assets\Plugins\Best HTTP (Pro)\BestHTTP\Connections\ConnectionBase.cs:161)
    14. BestHTTP.HTTPManager:OnUpdate() (at Assets\Plugins\Best HTTP (Pro)\BestHTTP\HTTPManager.cs:679)
    15. BestHTTP.HTTPUpdateDelegator:Update() (at Assets\Plugins\Best HTTP (Pro)\BestHTTP\HTTPUpdateDelegator.cs:178)
     
  44. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @Jochanan

    It might be a corrupted cache entry. Is this happened only once, or it's a regular error?
     
  45. Jochanan

    Jochanan

    Joined:
    Nov 9, 2016
    Posts:
    85
    I saw it only couple of times yesterday after year of flawless usage. Do you have any recommendations how to cover this case?
     
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @Jochanan

    Thanks, it will be fixed in the next version.
     
    Jochanan likes this.
  47. Finity

    Finity

    Joined:
    Jan 25, 2013
    Posts:
    10
    Socket.IO: Can you distinguish client-side "disconnect" event from server-side "disconnect" event? (if server intentionally disconnected the player, client should not reconnect for example.)
     
  48. RickC

    RickC

    Joined:
    Dec 1, 2012
    Posts:
    4
    Its not clear to me if have support for creating a websocket server in unity.

    If you do, then I will purchase your software. If not, do you have any plans to include it in the future?

    Thanks
     
    Last edited: Sep 3, 2019
  49. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @Finity

    Yes. When the server disconnects a client, it sends a disconnect packet, so the client know that it must not try to reconnect.
     
  50. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @RickC

    The plugin has client side support only for websocket (and for all the other protocols) and i do not plan to add server functionality.