SignalR IOS client, web socket transport cannot call the method from server


Cihan Akka

I am using SignalR-ObjC Client to provide communication between IOS application and .Net server.

I can connect using longpulling and call methods from a self-hosted cross-origin server without any errors. But due to my application needs, I have to use WebSocket. I have a Singleton Manager like:

@implementation SignalRManager
static int reconnectingTry;
+ (id)sharedManager {
    static SignalRManager *sharedHttpManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedHttpManager = [[self alloc] init];
        sharedHttpManager.hubConnection = [SRHubConnection connectionWithURL:@"http://xxx:8080/signalr"];
        sharedHttpManager.proxy = [sharedHttpManager.hubConnection createHubProxy:@"myhub"];
    });

    return sharedHttpManager;
}
+(SRHubProxy *)proxy
{
    return [[SignalRManager sharedManager] proxy];
}

+(SRHubConnection *)connection
{
    return [[SignalRManager sharedManager] hubConnection];
}

+(void)start
{
    SRWebSocketTransport *transport = [[SRWebSocketTransport alloc] init];

    [[SignalRManager connection] start:transport];

}
+(void)stop
{
    [[SignalRManager connection] stop];
}

and im calling like:

 [[SignalRManager proxy] invoke:@"Hello" withArgs:[NSArray array]];

I make the connection and the server can call the client method, but when I try to call the method from the client to the server, I get a "Request failed: Bad Request (400)" error.

Dolkalmi

Seems to be related to the protocol (SRClientTransportInterface) implementation in SRWebSocketTransport.

in reality:

- (void)send:(id <SRConnectionInterface>)connection data:(NSString *)data completionHandler:(void (^)(id response, NSError *error))block;

and must

- (void)send:(id <SRConnectionInterface>)connection data:(NSString *)data connectionData:(NSString *)connectionData completionHandler:(void (^)(id response, NSError *error))block; 

Like the subclass, the implementation doesn't call the superclass (SRHttpBasedTransport) method, so you get "Request failed: Bad Request (400)" (it's another http request, not websocket).

To fix this, just open the file SRWebSocketTransport.m in the Pods project and change the implementation as follows:

- (void)send:(id<SRConnectionInterface>)connection data:(NSString *)data connectionData:(NSString *)connectionData completionHandler:(void (^)(id response, NSError *error))block {
    [_webSocket send:data];

    if(block) {
        block(nil,nil);
    }
}

Hope this helps you.

pd: only check github seems to be fixed in feature-2.0.0.beta1 branch

Related


SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so that my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so that my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so that my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

SignalR cannot call method on server

Ben Black I'm using AngularJS to create a SignalR service that connects to a hub I specify and exposes .onand .invokemethods so my controllers can listen to events from the server and call methods on the server. Here is the relevant part of my service:

Call signalR server in PC from ios client in Mac

username I got this server code in the form here with this client from the same author here So the .Net signalR server runs on the PC. signalR is self-hosted in a console application. The client is an ios client written in Swift in my iMac. I am trying to writ

Call signalR server in PC from ios client in Mac

username I got this server code in the form here with this client from the same author here So the .Net signalR server runs on the PC. signalR is self-hosted in a console application. The client is an ios client written in Swift in my iMac. I am trying to writ

How to call client method from server using socket.io

username I am using flask-socketio for the server and have the following code to call client functions from the server. Is this the correct way? Or, there is a better way server @socketio.on('connect', namespace='/test') def test_connect(): sleep(5) em

How to call client method from server using socket.io

username I am using flask-socketio for the server and have the following code to call client functions from the server. Is this the correct way? Or, there is a better way server @socketio.on('connect', namespace='/test') def test_connect(): sleep(5) em

How to call client method from server using socket.io

username I am using flask-socketio for the server and have the following code to call client functions from the server. Is this the correct way? Or, there is a better way server @socketio.on('connect', namespace='/test') def test_connect(): sleep(5) em

How to call client method from server using socket.io

username I am using flask-socketio for the server and have the following code to call client functions from the server. Is this the correct way? Or, there is a better way server @socketio.on('connect', namespace='/test') def test_connect(): sleep(5) em

How to call client method from server using socket.io

username I am using flask-socketio for the server and have the following code to call client functions from the server. Is this the correct way? Or, there is a better way server @socketio.on('connect', namespace='/test') def test_connect(): sleep(5) em

Call SignalR Client from Web API Controller

Vince Black Following the following scenario: I have an ASP.NET Web Api running a SignalR hub and providing a SPA. SignalR hub is used to communicate with multiple C# SignalR clients. Now I want to retrieve data from a specific client and return this data from

Call the signalR method in the client method

Suresh I am using SignalR version 2.1.2. I am using a console application as SignalrClient. I call method A, and after getting the response, I have to call method B based on the response from method A. In this case, I am able to successfully call method B with

Call the signalR method in the client method

Suresh I am using SignalR version 2.1.2. I am using a console application as SignalrClient. I call method A, and after getting the response, I have to call method B based on the response from method A. In this case, I am able to successfully call method B with

Web socket server with IOS client compatibility

Raoul Hill I am trying to develop an IOS application that will establish a socket connection to a server. For the client side, I plan to use the SocketRocket library, and I try to code my socket server preferably in Node.js. Can anyone suggest which socket ser

Web socket server with IOS client compatibility

Raoul Hill I am trying to develop an IOS application that will establish a socket connection to a server. For the client side, I plan to use the SocketRocket library, and I try to code my socket server preferably in Node.js. Can anyone suggest which socket ser

Call SignalR Client method from normal C# class

Ravi Mittal I am trying to add SignalR in my MVC project . I need to call SignalR client methods from my class library. I did the following code public class CommomHubManager : ICommomHubManager { readonly IHubContext Context; public Commom

Call SignalR Client method from normal C# class

Ravi Mittal I am trying to add SignalR in my MVC project . I need to call SignalR client methods from my class library. I did the following code public class CommomHubManager : ICommomHubManager { readonly IHubContext Context; public Commom

Cannot return value from SignalR client by other method

Jacob Ja Shanks I'm developing a Winforms application that executes SQL procedures through a SignalR client. I'm relatively new to using SignalR and still wrapping my head around it. I first run my connect method to establish a connection to my SignalR service

Cannot return value from SignalR client by other method

Jacob Ja Shanks I'm developing a Winforms application that executes SQL procedures through a SignalR client. I'm relatively new to using SignalR and still wrapping my head around it. I first run my connect method to establish a connection to my SignalR service

SignalR - How to call hub method on server from server

username I have SignalR working between an ASP.NET (formerly MVC) server and a Windows Service client, because the client can call methods on the Server Hub, which are then displayed to the browser. The hub code is: public class AlphaHub : Hub {