Stopping SignalR-connection is slow - asp.net

Stoping SignalR connection of Javascript client is slow (around 30 seconds).
I use SignalR, version 2.0.1 (but problem reproduced in 2.0.0 ) for webchat integrated to ASP.NET site. I have one .NET SignalR client(for other reason) and a lot of JS clients (chat clients). My test case is very simple. I want to disable chat on ASP.NET page. For this reason I try to stop SignalR connection using next code:
$.connection.hub.stop();
But onDisconnected method (on hub) was calling only after 30 seconds. I suppose that connection was stopped by disconnect timeout but not by Javascript code. I use LongPolling transpot by default.
var initObject = { transport: ["longPolling", "webSockets", "foreverFrame", "serverSentEvents"] };
$.connection.hub.start(initObject).done(function () {
...
}
Problem reproduce in last versions of Google Chrome but works fine in IE and Mozilla. What reason of so strange behaviour of SignalR and how can I avoid it?

For anyone else having this issue just use conn.Stop(new TimeSpan(0)) to kill the connection instantly.

conn.disconnect();
conn.stop();
hub.subscribe(null);
conn = null;
hub= null;
try this and let me know if it works.It works in android though.

The problem is solved by updating SignalR version to the 2.0.3.

Related

Xamarin Android project cannot connect to localhost API

I have been working on this problem for quite some time. I've read the many similar posts and their solutions don't help me (many posts are old and stale). I have a new Xamarin project and a localhost API that I am testing to. Initially I installed our production API locally and it doesn't connect. So I created a smaller test API and have had varying results in connecting. Xamarin Android will not connect with a "Failed to connect to localhost:XXXXX" message. I built a WPF project and get the same results. However I can connect to outside public API's (github) with both. I can connect to my localhost with a Windows forms desktop app and successfully get & post. Postman and httprepl both connect locally and successfully get & post. A couple of the other things the other posts suggested are 1) Client handler to ignore SSL - doesn't work, 2) Use the emulator's browser to connect to localhost - cannot connect. (this might be exposing where the problem really is but not sure).
Also The debugger seems to be behaving oddly. When the debugger gets to the HttpResponseMessageresponse.... line it rarely makes it to the next line so I cannot inspect the statuscode. The block I have below is in a try/catch and rarely makes it to the catch if the connection truly fails. Sometimes it will be caught at the catch and that's how I get the "failed to connect" message. Another developer here has run the project on his computer and gets the same results/errors on his computer.
HttpResponseMessage response = await client.SendAsync(request);
var Statuscode = response.StatusCode;
if (response.IsSuccessStatusCode)
{
var jsonbody = response.Content.ReadAsStringAsync().Result;
var ResponseBody = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
}
else
{
string oops = "Nothing";
}
I seem to be running out of options and am looking for any advice.
Thanks in advance.

How do you initialize the Twilio Client in Meteor JS?

I'm having incredible difficulty setting up the Twilio Client in Meteor JS, and would really appreciate any help.
I have extracted the relevant code and error logs below. So far as I can tell, it should be simple. The code is just grabbing an authtoken which I have previously generated, and then trying to set up the device using that authtoken. But it's not working.
'click #initializeDevice'(event) {
var thisAuthToken = Session.get('myAuthToken');
console.log(thisAuthToken); // I have confirmed with Twilio support that these authtokens are correctly generated
const Device = require('twilio-client').Device;
Device.setup(thisAuthToken, { debug: true });
var myStatus = Device.status()
console.log(myStatus); //this is logging "offline"
Device.on('ready',function (device) {
log('Twilio.Device Ready!'); //this is not logging anything
});
},
When that code runs, it generates the following logs:
eyJhbGciDpvdXRnb2luZz9hcHBTaWQ9QVA2NDE2MzJmMzA1ZjJiY2I[Note:I have deleted part of the middle of the logged authtoken for the purpose of this public post]5YmMxOGQyOWVlNGU2ZGM0NjdmMzRiNDVhNCIsImV4cCI6MTU3Nz0ygbJKTx15GgNCWDkm-iUPjn_O1NZU6yovp4vjE
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Setting up VSP
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 WSTransport.open() called...
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Attempting to connect...
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Closing and cleaning up WebSocket...
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 No WebSocket to clean up.
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Could not connect to endpoint: ws does not work in the browser. Browser clients must use the native WebSocket object
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Closing and cleaning up WebSocket...
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 No WebSocket to clean up.
calltemplate.js:31 offline
I'm doing this all from a local server, tunneled through NGROK. I've also set up the Twilio back end, linked the app, purchased a number, etc.
So far as I can tell, the issue, from the logs, appears to be something to do with the way that Meteor uses WebSockets.
Could not connect to endpoint: ws does not work in the browser. Browser clients must use the native WebSocket object
This is a not a Meteor related problem rather than browser issue.
Make sure your browser supports WebRTC
BTW, Your browser might be supporting it but you'd need to enable it.

Why is my disconnect() handler not getting fired in SignalR Client Side JS?

I'm seeing some odd/unexpected behaviour using the SignalR 2.0.3 libraries.
I'm trying to hook some call backs in the client and they don't seem to be getting fired.
I'd really like to get the reconnecting, reconnected and disconnected call backs working in JS - client side.
SignalR does connect successfully and I've got communication between the server and client.
Here are a couple of code snippets:
$.connection.reconnecting = function () {
alert("reconnecting");
};
$.connection.reconnected = function () {
alert("We have been reconnected");
};
$.connection.disconnected = function () {
alert("We are disconnected!");
};
I could have sworn that I had these firing when I was using SignalR 1.x.
Currently, we using version 2.0.3.
I'm running a 2 machine setup where my server app (and hub) is on 1 machine.
Here are the steps I'm using to reproduce:
1) Connect from a second machine. I looked at the network traffic in the browser
console and it looks ok.
2) Next I disconnect the client machine from the network. In the console I see SignalR
attempting to reconnect. (This is as expected)
3) Ultimately after N retries, it looks like it disconnects. (I see the final retry is "Canceled"
in the console output.
4) However, my disconnected() handler does not get called.
Any insights or thoughts how to track this down?
Thanks,
JohnB
With SignalR 2.x, you can register your callbacks like this:
$.connection.hub.reconnecting(function() {
alert("reconnecting");
});
$.connection.hub.reconnected(function() {
alert("We have been reconnected");
});
$.connection.hub.disconnected(function() {
alert("We are disconnected!");
});
You can also add callbacks using $.connection.hub.stateChanged(). See documentation.

AFNetworking stopped working under iOS 6

I've noticed recently, that my code, that uses AFNetworking (latest version from master branch) stopped working properly under iOS 6.
Here's my code:
httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:baseURL]];
httpClient.operationQueue.maxConcurrentOperationCount = 1;
where httpClient is a class variable.
Next, I'm creating a request:
NSMutableURLRequest *signInRequest = [httpClient requestWithMethod:#"POST" path:#"/user/register" parameters:dataToSend];
signInRequest.timeoutInterval = 15.0;
signInRequest.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
AFJSONRequestOperation *signInOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:signInRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
// Blah
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
// Blah
}];
[httpClient enqueueHTTPRequestOperation:signInOperation];
All the other requests are constructed similarly. The first enqueued operation works well, I can get into success handler block. However, next calls to other requests are finished with fail handler and request timeout error, no matter how big is timeout value I choose.
I have done the same calls using plain NSURLConnection, writing a tons of code :), with success, requests were processed properly.
I switched to iOS 5 device, and the code above works fine.
I switched to 3G connection (iOS 6), and the code above works.
It seems like I have this problem only on WiFi connections (except the case when I'm in the same subnet with my REST server.)
Any thoughts on this?
Thank you in advance.
It seems you also posted an issue on AFNetworking's github and found the solution yourself :)!
It seems like iOS 6 changes something to TCP implementation or something. I moved server to third-party hosting and it is working now.
For future readers, the issue can be found here.

How to detect the internet connection in sencha touch

I have a small application based on Sencha touch. this application should submit data to the server lets say this is an example of Ajax call that I did
Ext.Ajax.request({
url: 'http://www.google.com',
timeout:30*1000,
success: function(response, opts) {
console.dir('success');
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}
Now the
failure
never gets called if I have a network connection but without internet !! the problem that I have my client does not have a solid internet connection but he has a wifi all the time !
So , everything I found on the net detect if I have a Network connection ! but I already have one but this connection does not provide Internet.
anyone knows how to detect the Internet connection not the Network?
FYI : I tried the navigator.online and the network state examples all of them does not detect internet, also I attached a phoneGap listener since I'm using sencha with phoneGap to create a iOS app !
EDIT: I'm using Sencha v1.1
alert(Ext.device.Connection.isOnline());
Here's url,
http://docs.sencha.com/touch/2-0/#!/api/Ext.device.Connection
You can also detect the connection using PhoneGap. See: http://docs.phonegap.com/en/1.9.0/cordova_connection_connection.md.html
If the success callback is being invoked, then you best check the response parameter for null and/or length. If you find null or zero length, then assume the request failed.

Resources