Actionscript services stop functioning - actionscript-3

I have built a complex AIR application which has been successfully running for quite some time of many PCs. Unfortunately, I have a plaguing problem with internet connectivity and I was wondering if anyone had encountered this issue before.
Every once in a while, the program will completely stop talking to the internet (all services start faulting). I wrote special code in my program to monitor the situation in which I use two different services to contact the same server.
The first service:
var req:URLRequest = new URLRequest("myURL.com");
this.urlMonitor = new URLMonitor(req, [200, 304]); // Acceptable status codes
this.urlMonitor.pollInterval = 60 * 1000; // Every minute
this.urlMonitor.addEventListener(StatusEvent.STATUS, onStatusChange);
this.urlMonitor.start();
private function onStatusChange(e:StatusEvent):void
{
if (this.urlMonitor.available)
{
pollStatusOnline = true;
Online = true;
}
else
{
pollStatusOnline = false;
Online = false;
}
}
The secondary method is a normal HTTP Service call:
checkInService = new HTTPService();
checkInService.method = "POST";
checkInService.addEventListener(ResultEvent.RESULT,sendResult);
checkInService.addEventListener(FaultEvent.FAULT, faultResult);
checkInService.addEventListener(InvokeEvent.INVOKE, invokeAttempt);
checkInService.url = "myURL.com";
checkInService.concurrency = Concurrency.LAST;
checkInService.send(params);
These two services point to the same location and work 98% of the time. Sometimes, after a few hours, I have noticed that both services no longer can connect to the website. The HTTP Service returns a StatusCode 0. I am able to open command prompt and ping the server directly with no problem from the PC which is failing. The services will not function again until the program is restarted.
I have been working on this issue for many months now without resolution. If anyone is able to even point me in a somewhat possible, maybe this might be the problem, possibly, direction, I would really appreciate it.
Thank you in advance.

Check the code value of the StatusEvent you receive from the URLMonitor - this might give more info than the HTTPService (you might also want to try passing a null value to URLMonitor constructor, to widen the acceptable status codes).
If you have access to the server(s?) in question, check their logs. Could the server config have changed such that it might now consider such frequent requests as flooding?
You should also be able to use an HTTP debugger like Fiddler or Charles on the client machine to see more information about the requests going out of your application.

Related

Interrupted downloads when downloading a file from Web Api (remote host closed error 0x800704CD)

I have read near 20 other posts about this particular error, but most seem to be issues with the code calling Response.Close or similar, which is not our case. I understand that this particular error means that typically a user browsed away from the web page or cancelled the request midway, but in our case we are getting this error without cancelling a request. I can observe the error just after a few seconds, the download just fails in the browser (both Chrome and IE, so it's not browser specific).
We have a web api controller that serves a file download.
[HttpGet]
public HttpResponseMessage Download()
{
//
// Enumerates a directory and returns a Read-only FileStream of the download
var stream = dataProvider.GetServerVersionAssemblyStream(configuration.DownloadDirectory, configuration.ServerVersion);
if (stream == null)
{
return new HttpResponseMessage(HttpStatusCode.NotFound);
}
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(stream)
};
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = $"{configuration.ServerVersion}.exe";
response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Application.Octet);
response.Content.Headers.ContentLength = stream.Length;
return response;
}
Is there something incorrect we are doing in our Download method, or is there something we need to tweak in IIS?
This happens sporadically. I can't observe a pattern, it works sometimes and other times it fails repeatedly.
The file download is about 150MB
The download is initiated from a hyperlink on our web page, there is no special calling code
The download is over HTTPS (HTTP is disabled)
The Web Api is hosted on Azure
It doesn't appear to be timing out, it can happen just after a second or two, so it's not hitting the default 30 second timeout values
I also noticed I can't seem to initiate multiple file downloads from the server at once, which is concerning. This needs to be able to serve 150+ businesses and multiple simultaneous downloads, so I'm concerned there is something we need to tweak in IIS or the Web Api.
I was able to finally fix our problem. For us it turned out to be a combination of two things: 1) we had several memory leaks and CPU intensive code in our Web Api that was impacting concurrent downloads, and 2) we ultimately resolved the issue by changing MinBytesPerSecond (see: https://blogs.msdn.microsoft.com/benjaminperkins/2013/02/01/its-not-iis/) to a lower value, or 0 to disable. We have not had an issue since.

How to find out the availability status of a Web API from a Windows Store application

I have a Line-of-Business (LoB) Windows 8.1 Store application I developed for a client. The client side-loads it on several Windows 10 tablets. They use it in an environment where WiFi is spotty at best and they would like to get some sort of notification inside the app, regardless of what page they are on, notification that will let them know that they've lost connectivity to the network. I have created a method on my Web API that is not hitting the repository (database). Instead, it quickly returns some static information regarding my Web API, such as version, date and time of the invocation and some trademark stuff that I'm required to return. I thought of calling this method at precise intervals of time and when there's no response, assume that the Web API connectivity is lost. In my main page, the first one displayed when the application is started, I have the following stuff in the constructor of my view model:
_webApiStatusTimer = new DispatcherTimer();
_webApiStatusTimer.Tick += OnCheckWebApiStatusEvent;
_webApiStatusTimer.Interval = new TimeSpan(0, 0, 30);
_webApiStatusTimer.Start();
Then, the event handler is implemented like this:
private async void OnCheckWebApiStatusEvent(object sender, object e)
{
// stop the timer
_webApiStatusTimer.Stop();
// refresh the search
var webApiInfo = await _webApiClient.GetWebApiInfo();
// add all returned records in the list
if (webApiInfo == null)
{
var messageDialog = new MessageDialog(#"The application has lost connection with the back-end Web API!");
await messageDialog.ShowAsync();
// restart the timer
_webApiStatusTimer.Start();
}
}
When the Web API connection is lost, I get a nice popup message that informs me that the Web API is no longer available. The problem I have is that after a while, especially if I navigate away from the first page but not necessary, I get an UnauthorizedAccessException in my application.
I use the DispatcherTimer since my understanding is that this is compatible with
UI threads, but obviously, I still do something wrong. Anyone cares to set me on the right path?
Also, if you did something similar and found a much better approach, I'd love to hear about your solution.
Thanks in advance,
Eddie
First, If you are using Windows Store Apps, then you could possibly use a Background task to check poll for the status of the web api instead of putting this responsibility on your view model, its not the viewmodels concern
Second, if you are connecting from your Windows store app to your API then one successful authentication/ authorization for the first time, how and where do you store the token (assuming you are using token authentication). If you are (and ideally you should), is there a timer that you start which is set to the token expiration time? Is your local storage getting flushed somehow and loosing the aurthorization data?
Need more information.

InstanceContextMode.Single in WCF wsHttpBinding,webHttpBinding and REST

I have recently started development on a relatively simple WCF REST service which returns JSON formatted results. At first everything worked great, and the service was quickly up and running.
The main function of the service is to return a large chunk of data extracted from a database. This data rarely changes, so I decided to try and setup a caching mechanism to speed things up. To do this I planned to set InstanceContextMode.Single and ConcurrencyMode.Multiple, and then with some thread locks, safely return a static cached result. Every 5 minutes or so, or whenever IIS decides to clear everything, the data would be re-fetched from the database.
My issue is InstanceContextMode.Single does not behave as expected. My understanding is a single instance of my WCF service class should be created and maintained. However the behaviour I have is a completely new instance of my Class is created per call. This include re-initialising all static variables.
I tried changing the web service from webHttpBinding (used for REST) to wsHttpBinding and using the service as a SOAP config, but this results in exactly the same behaviour.
What am I doing wrong!!! Have spent way too long trying to figure this out.
Any help would be great!.
Strange, can you try this and tell me what happen then?
ServiceThrottlingBehavior ThrottleBehavior = new ServiceThrottlingBehavior();
ThrottleBehavior.MaxConcurrentSessions = 1;
ThrottleBehavior.MaxConcurrentCalls = 1;
ThrottleBehavior.MaxConcurrentInstances = 1;
ServiceHost Host = ...
Host.Description.Behaviors.Add(ThrottleBehavior);
And [how] do you know your single service instance isn't "Single"? You saw multiple database connection from profiler? Is that what suggested to you why your service isn't a single instance? From your service operation implementation, do you do some of the work on a separate thread?

NetStream.send not working with NetGroup in RTMFP

We are running a Cumulus server to do a live voice and text chat.
The setting is that each client can post data to each other client in the same NetGroup via group.post(). Unfortunately, that function is extremely slow (half a second delay, at least), so we switched to using NetStream.send to call functions on other clients, passing the data through that. This works almost instantly.
However, we are now trying to build separate chat rooms, using different NetGroups. But when doing so, NetStream.send() doesn't work anymore, the functions are never called on the other clients, and no voice data is transferred. Basically, the whole publishing NetStream seems to be not working any more.
We have the following setup to establish a NetGroup and a publishing stream on each client:
var gspec:GroupSpecifier = new GroupSpecifier("Group1");
gspec.multicastEnabled = true;
gspec.postingEnabled = true;
gspec.serverChannelEnabled = true;
gspec.objectReplicationEnabled = true;
gspec.routingEnabled = true;
_group = new NetGroup(_netConnection, gspec.groupspecWithAuthorizations());
_group.addEventListener(NetStatusEvent.NET_STATUS, handleNetGroupStatus);
_sendStream = new NetStream(_netConnection, gspec.groupspecWithAuthorizations());
_sendStream.addEventListener(NetStatusEvent.NET_STATUS, handleNetStreamStatus);
_sendStream.client = this;
_sendStream.attachAudio(_mic);
_sendStream.publish("media");
And the following code is used to listen to the "media" stream:
case "NetGroup.Neighbor.Connect":
var netStream :NetStream = new NetStream(_netConnection, p_netStatusEvent.info.peerID);
netStream.addEventListener(NetStatusEvent.NET_STATUS, handleNetStreamStatus);
netStream.client = this;
netStream.play("media");
break;
The NetGroup connection itself works, and "NetGroup.Neighbor.Connect" is called on each client when a neighbor connects. But the _sendStream itself simply doesn't work. No data is received, no function called.
It does work when the publishing NetStream is constructed in the following way:
_sendStream = new NetStream(_netConnection, NetStream.DIRECT_CONNECTIONS);
However, we only want the NetStream to send to a single NetGroup, and according to the Adobe Documentation, using gspec.groupspecWithAuthorizations() in the constructor should allow exactly that.
Are we missing something here?
I found the answer:
You also have to make the receiving NetStream listen to gspec.groupspecWithAuthorizations() instead of p_netStatusEvent.info.peerID.
This does work. Unfortunately, this makes voice chat impossible, as it is incredibly slow (as slow as NetGroup.post()) and introduces many sound artifacts.
So, we'll have to find another solution for different chat rooms...

Socket Policy File Server & AIR3.0

Edit: So i'm trying to connect to a IRC server using AIR3.0. No matter what, i always get
:server_ip NOTICE AUTH :*** Looking up your hostname...
:server_ip NOTICE AUTH :*** Found your hostname (cached)
ERROR :Closing Link: [server_ip] (Ping timeout)
Here is just a bunch of code :
private function handleSocketData(__e:ProgressEvent):void {
receiveData();
}
private function receiveData():void{
var str:String =_socket.readUTFBytes(_socket.bytesAvailable);
txt.text += str;
}
private function sendData(__str:String):void{
_socket.writeUTFBytes(__str);
_socket.flush();
}
I just do a classic _socket.connect(server_ip, server_port); and i have a bunch of listeners for the socket like ProgressEvent.SOCKET_DATA, Event.CLOSE, Event.CONNECT ...
Nothing fancy.
But no matter what, i can connect to the irc server, but it always stops at Found your hostname then nothing happens (no more data is sent my way) and i get a disconnection a few seconds after...
AIR doesn't require a socket policy, only Flash does, so that's not your issue here. Unfortunately I can't tell you what the real problem is based on the information you've posted. Please provide more details and maybe someone can tell you what the real problem is.