Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to return after waiting for 10 seconds. #26

Closed
NuelNikhil opened this issue Feb 2, 2016 · 18 comments
Closed

Failed to return after waiting for 10 seconds. #26

NuelNikhil opened this issue Feb 2, 2016 · 18 comments
Labels

Comments

@NuelNikhil
Copy link

I have been trying SwiftR for a week. but when I ran the project I got nothing. In viewDidLoadMethod I have set this code

 SwiftR.connect("http://maisad-001-site1.btempurl.com/signalr/") { connection in
            let simpleHub = connection.createHubProxy("maisAdChatHub")
            print("HUBBBBB   \(simpleHub)")
                        SwiftR.startAll()
            print("HUBBBBB1   \(simpleHub)")
            // Event handler
            simpleHub.on("newMessage") { args in
//                let message = args!["0"] as! String
//                let detail = args!["1"] as! String
                print("Send Messageeeeeeeee")
                print("Response : \(args)")


                // Invoke server method
              //  simpleHub.invoke("sendSimple", arguments: ["Simple Test", "This is a simple message"])

                // Invoke server method and handle response
                simpleHub.invoke("sendmessage", arguments: ["Simple Test", "Room1" , "Usernamee" , "photo"]) { (result, error) in
                    if let e = error {
                        print("Error message: \(e)")
                    } else {
                        print("Success!")
                        if let r = result {
                            print("Result: \(r)")
                        }
                    }
                }

            }
        }
    }

I put a breakpoint at line number 7 where simpleHub.on("newMessage") is called am getting a message in console and it is

2016-02-02 15:04:33.131 CHATAPP[3089:374824] void SendDelegateMessage(NSInvocation *): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode

No Idea whats's going wrong... Need help!!!

@adamhartford
Copy link
Owner

You should only get that error message when debugging. The WebView stops executing JavaScript calls after 10 seconds. You will only hit that when you set a breakpoint somewhere in code that's part of a JavaScript callback. It's on my todo list to look at that, but it's been a very low priority since it's really been a non-issue so far.

As far as your code above, I see a few issues. I would suggest you try to get the demo app working with your server and go from there. The code should look more like this:

SwiftR.connect("http://maisad-001-site1.btempurl.com/signalr/") { connection in
    let simpleHub = connection.createHubProxy("maisAdChatHub")

    // Event handler
    simpleHub.on("newMessage") { args in
        print("Send Messageeeeeeeee")
        print("Response : \(args)")
    }

    connection.connected = {
        // Invoke server method and handle response
        simpleHub.invoke("sendmessage", arguments: ["Simple Test", "Room1" , "Usernamee" , "photo"]) { (result, error) in
            if let e = error {
                print("Error message: \(e)")
            } else {
                print("Success!")
                if let r = result {
                    print("Result: \(r)")
                }
            }
        }
    }
}

You don't need to call SwiftR.startAll(). You have everything happening in a callback handler for newMessage, so nothing will be invoked until the server sends newMessage to the client. Your simpleHub variable is also declared in the closure, so you can't access it anywhere else in your app. See the demo app for a different usage.

Lastly, it looks like you want to invoke a SignalR server method as soon as the client is connected, so I've tried to update your code accordingly. There's a callback for when the client has actually connected.

If you look at the code I've proposed above, you'll see that it:

  1. Declares a hub.
  2. Declares response callback for newMessage.
  3. Invokes the server method sendmessage as soon as the client has established a SignalR connection.

This series of steps results in the newMessage callback handler being invoked as soon as possible after the view is loaded. I've run this code against my own test server to verify that it works.

From here, you'll just have to make sure your server methods are defined correctly, you're using the right names, etc.

@NuelNikhil
Copy link
Author

I was looking for your @adamhartford comments and I got what I was looking for... Let me try ... 👍

@NuelNikhil
Copy link
Author

@adamhartford I tried running the SwiftR iOS Demo project. but I got this message in console

Starting...
Error: Optional({
    column = 4521;
    context =     {
        readyState = 0;
        status = 0;
        statusText = error;
    };
    errorMessage = "Error during negotiation request.";
    line = 8;
    source =     {
        readyState = 0;
        status = 0;
        statusText = error;
    };
    sourceURL = "file:///Users/user/Library/Developer/CoreSimulator/Devices/AB259C83-FD3F-4ABF-8F54-A8E07610B9D4/data/Containers/Data/Application/222A984A-58E4-4253-92F5-3F00955FEBE0/tmp/jquery.signalR-2.2.0.min";
})
Disconnected.

@adamhartford
Copy link
Owner

That means there's something wrong with your server. (Did you make sure the URL is correct?) What happens when you browse to http://maisad-001-site1.btempurl.com/signalr/hubs in a browser both on your desktop and on your phone?

@NuelNikhil
Copy link
Author

I get the javascript code while browsing to http://maisad-001-site1.btempurl.com/signalr/hubs

@adamhartford
Copy link
Owner

OK, well that's a good sign. I think you should try to write a simple test page that uses the SignalR JavaScript client to test your server. If that works, there's no reason your iOS app shouldn't work as well. You could also try running Charles Proxy to inspect the traffic to your server. I've run the same code against my server and it works, so I'd probably need to see more of your iOS/.NET code to help you.

@NuelNikhil
Copy link
Author

well .....I have tried the same code I got from your Github page in your server , and tried the code you made above...

@adamhartford
Copy link
Owner

Have you tried Charles Proxy? Watch the traffic to the server, see what's happening? Also, what version of SignalR are you using?

@NuelNikhil
Copy link
Author

This server is working fine for a developer who is creating a hybrid application. I don't know why it's not working for me.... and when I used Charles proxy it showed a 400 error... 👎

@adamhartford
Copy link
Owner

A 400 is expected when browsing to /signalr. You should get a 200 with /signalr/hubs. Do you have CORS enabled on your server?

// Server
app.UseCors (CorsOptions.AllowAll);

When you browse to /signalr/hubs, what version of the JavaScript library does it return?

@NuelNikhil
Copy link
Author

I am currently using SignalR version v2.2.0 and javascript library version returned is v2.1.1 and of-course I have enabled CORS in my server...

@adamhartford
Copy link
Owner

Are you positive about CORS? I notice both URLs you've posted here are publicly available, so I tried both with WKWebView and get:

Origin null is not allowed by Access-Control-Allow-Origin.

That indicates CORS is not enabled. If I use UIWebView, the server returns an error (500).

Correction: your btempurl.com returns a 500 with UIWebView. The cynere.net connects OK.

@adamhartford
Copy link
Owner

Now I see: "You are using a version of the client that isn't compatible with the server. Client version 1.5, server version 1.4."

I don't know how you're using SignalR 2.2.0, but get 2.1.1 JavaScript. You should see 2.2.0 in the JavaScript as well.

If using NuGet, can you double check your packages? And maybe make sure you haven't deployed multiple versions of SignalR?

@NuelNikhil
Copy link
Author

Sorry @adamhartford .... I am using signalr ver 2.1.1. it's my mistake I checked it in the nuget online packages rather than in the installed packages... I tried a lot with SWIFTR but it didn't even work. being new with iOS development I am not able get how your library works and what I need add to my code. I will try again. I will let you know my result's.... 👍

@NuelNikhil
Copy link
Author

Hi.. @adamhartford Now I got a 200 status as response in by using charles. I took the Url from Charles and got this in browser {"Url":"/signalr/signalr","ConnectionToken":"XPOVLO+P+t6r+m3r+Lr1CqchnP8KMi3eljkg6M7JZ0xwRk+C2Za73XMZC05uRQRN552XsBYGu40VfvvRmNUQdNQhPMjR8f0OSnu4RVF8nCVyTXYOvijqffDgA7SQgJyP","ConnectionId":"4537d793-960a-49ab-b684-b3b917acd7af","KeepAliveTimeout":20.0,"DisconnectTimeout":30.0,"TryWebSockets":false,"ProtocolVersion":"1.4","TransportConnectTimeout":5.0,"LongPollDelay":0.0}

but in the demo project the code rans to the error section as I have shown in the above question.

@adamhartford
Copy link
Owner

Looks like you're still using SignalR 2.1.1 instead of 2.2.0. Then, if you're still using the demo project, make sure you replace simpleHub with Hub1 (which I can see in your JavaScript). Then make sure your sendSimple only sends one argument, not two like the demo (again I can see from your /signalr/hubs JS). That should work.

Also, I have a development version of SwiftR where you can now specify the server version you're using:

SwiftR.signalRVersion = .v2_1_1

I might change this API depending on what versions I can support, but I can confirm that with my suggested changes above (and using 2.1.1), everything works.

Fo now, you'll need to make those changes, and be sure to run SignalR version 2.2.0.

@NuelNikhil
Copy link
Author

one of our developer is working with a hybrid app and he uses signalr too. I used his server to test whether my code works , I have changed signalr version to 2.2.0 and did whatever I needed to but still no change .

@NuelNikhil
Copy link
Author

@adamhartford Thank you for the replies you made all the time. Now everything is working fine... 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants