Giter VIP home page Giter VIP logo

Comments (17)

moozzyk avatar moozzyk commented on August 29, 2024

How does the hub method look like on the server side?

from signalr-client-swift.

NileshKalathiya avatar NileshKalathiya commented on August 29, 2024

i'm getting response here "createHubMessage(payload: Data)" but in invocationDidComplete always nil.

and then said "No handler registered for method 'market'"

from signalr-client-swift.

moozzyk avatar moozzyk commented on August 29, 2024

Because I don't know how the server side hub method looks like I can only speculate. I think your server side hub method is void and it invokes the client method. If this is the case your handler does not have any value because it is void on the server side and is invoked to let you know that the server side hub method invocation completed without error. The error: "No handler registered for method 'market'" indicates you invoked a client side method from the server but you have not registered any handler to handle this invocation.
If this is not the case or you need more information you need to show me code - a simplified repro (remove as much logic as you can) is the best.

from signalr-client-swift.

NileshKalathiya avatar NileshKalathiya commented on August 29, 2024
public async Task MarketRefresh(int baseCurrencyId) {
   object[] param = {
    new SqlParameter("@BaseCurrencyId", baseCurrencyId)
   };
   var dr = await SqlHelper.SqlHelper.ExecuteReaderAsync(
    this.connectionStrings.Value.BuucoinExchange,
    "GetMarketData",
    param);
   var lst = new List<Dictionary<string, object>>();
   while (await dr.ReadAsync()) {
    var obj = new Dictionary<string, object>();
    for (var i = 0; i < dr.FieldCount; i++) {
     obj[dr.GetName(i)] = dr[i].GetType().Name == "DBNull" ? null : dr[i];
    }
    lst.Add(obj);
   }

   await this.Clients.All.SendAsync("marketRefresh", lst);
  }

this is my method.

from signalr-client-swift.

moozzyk avatar moozzyk commented on August 29, 2024

So, the server method does not return any value (it returns a Task which is an async equivalent to void). This explains why you never see any result in your handler. Since the hub method does not return value you should use the invoke overload that does not take the return type.
To see data sent by await this.Clients.All.SendAsync("marketRefresh", lst); you need to register a handler on the client. It would look something like that:

chatHubConnection!.on(method:"marketRefresh", callback: { args, _ in 
...
})

One caveat is that I don't think it will work with the values you are sending. From the server side you are sending a Dictionary of objects and I am pretty sure that the client will not know how to handle the data it returns. I have started looking at the Codable protocol (#35) but have not implemented it yet and the client only recognizes primitive types by itself. You can make it work wit complex types if you implement the TypeConverter protocol.

from signalr-client-swift.

NileshKalathiya avatar NileshKalathiya commented on August 29, 2024

thank you @moozzyk now it's working using
chatHubConnection!.on(method:"marketRefresh", callback: { args, _ in
...
})

from signalr-client-swift.

moozzyk avatar moozzyk commented on August 29, 2024

No problem! Out of curiosity - how do you handle the argument? Did NSDictionary actually work?

from signalr-client-swift.

NileshKalathiya avatar NileshKalathiya commented on August 29, 2024

chatHubConnection!.on(method:"marketRefresh", callback: { args, _ in
...
})

chatHubConnection?.invoke(method: "marketRefresh", arguments: [OrderID], returnType: Any.self, invocationDidComplete: { (args, error) in

})

call method like this. both at a time.

from signalr-client-swift.

moozzyk avatar moozzyk commented on August 29, 2024

Thanks! I will close the issue now since the question has been answered.

from signalr-client-swift.

rishbaranwal avatar rishbaranwal commented on August 29, 2024

I am not able to send Any.self as result type

Getting Below Error, Please help

Protocol type 'Any' cannot conform to 'Decodable' because only concrete types can conform to protocols

    self.liveSpaceHubConnection!.invoke(method: "getlatestspacecount", 1, resultType: Any.self, invocationDidComplete: { (args, error) in
        if error == nil {
            print(args ?? "Not Found")
        } else {
            print(error?.localizedDescription ?? "Error")
        }
    })

from signalr-client-swift.

moozzyk avatar moozzyk commented on August 29, 2024

from signalr-client-swift.

rishbaranwal avatar rishbaranwal commented on August 29, 2024

Message received: {"type":1,"target":"getlatestspacecount","arguments":[[{"spaceTypeId":2,"spaceTypeName":"MeetingRoom","totalCount":4,"availableCount":4},{"spaceTypeId":1,"spaceTypeName":"Workstation","totalCount":4,"availableCount":4},{"spaceTypeId":3,"spaceTypeName":"JITRoom","totalCount":4,"availableCount":3},{"spaceTypeId":4,"spaceTypeName":"FocusArea","totalCount":4,"availableCount":4}]]}

The above is the response that I received from server,

I am quite confuse, how I can read/parse this response

Please help!!

from signalr-client-swift.

moozzyk avatar moozzyk commented on August 29, 2024

Your server is sending a collection of structured object. You need to create a corresponding struct/class in Swift so that the client could materialize this payload. For instance if you look at the tests the following hub method on the server side returns a collection of structural objects:

public IEnumerable<Person> SortByName(Person[] people)
{
return people.OrderBy(p => p.LastName).ThenBy(p => p.FirstName);
}

Here is how the type is defined on the server side:

namespace TestServer
{
public enum Sex { Male, Female }
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int? Age { get; set; }
public double? Height { get; set; }
public Sex? Sex { get; set; }
}
}

on the client side the corresponding type looks like this:

enum Sex: Int, Codable {
case Male
case Female
}
struct User: Codable {
public let firstName: String
let lastName: String
let age: Int?
let height: Double?
let sex: Sex?
}

(as a side note, I believe you don't need to explicitly mark that the struct is Codable - I think if all members are Codable the struct will automatically be Codable) and is invoked as follows:

hubConnection.invoke(method: "SortByName", arguments: [input], resultType: [User].self, invocationDidComplete: { people, error in
XCTAssertNil(error)

This seems to be exactly what you are after - even the return type is an array.

P.S. Next time please open a new issue instead of hijacking an existing issue which is not only unrelated but also closed.

from signalr-client-swift.

rishbaranwal avatar rishbaranwal commented on August 29, 2024

Sorry about the inconvenience, will definitely take care next time

Able to do solve the issue from above snippets, however getting this below error

error: No handler registered for method 'getlatestspacecount'
It's not possible to set callback with invoke method, Please clarify

Thanks for help.. :)

from signalr-client-swift.

moozzyk avatar moozzyk commented on August 29, 2024

Handlers are registered like this:

hubConnection.on(method: "GetNumber", callback: { argumentExtractor in

from signalr-client-swift.

rishbaranwal avatar rishbaranwal commented on August 29, 2024

Got it thanks for help, already did that, just wondered , if I can pass with invoke method

from signalr-client-swift.

moozzyk avatar moozzyk commented on August 29, 2024

These are two different scenarios. If your server hub method returns a result you will get it as an input to the invocation completion handler. If the server is invoking a client hub method you will get it as an argument in the client method handler.

from signalr-client-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.