Arduino HTTP request loop fails after first loop - c#

im trying to make a HTTP request loop, however, it seems to fail after the first time. i have no idea why this is happening, ive had a look around online and it's something to do with closing the request and then restarting it(i think), but i cant seem to do it?
my loop code is available here http://pastie.org/4199450
i get the following when i run it:
SUCCESS!
connection failed
connection failed
..
Anyone got any ideas?

You are connecting to the server/port once without disconnecting after.
Then, you try to connect again but you are still connected. This may be the reason why the connection line fail the second times.

Related

The format of the specified network name is not valid : HTTPListener error on system restart

I have implemented an Http Listener in c# as a windows service. The windows service is set to start automatically when the machine is restarted. When I manually start the service after installing it, the http listener works fine and it responds to the requests it receives. But, when the service is started on a system restart, I get the following error:
System.Net.HttpListenerException (0x80004005): The format of the specified network name is not valid
I get this error on listener.Start().
The code of http listener is like this:
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://myip:port/");
listener.Start();
I got a suggestion from this already asked question. If I follow what's given in the answer, it still doesn't work.
Furthermore, I tried running:
netsh http show iplisten
in powershell, the list is empty. Even when the http listener works (when the first time I install the service and run it), the output of this command is empty list. So I don't think this is an issue.
Any suggestions will be really helpful.
Answering my own question. It seems there are some other services that need to be running for us to be able to start an http listener. These are not yet started by the time windows starts my service. I found two solutions for this, one is to use delayed start
sc.exe config myservicename start=delayed-auto
The other is to have a try catch while starting the http listener, and if it fails, try again after a few seconds. In my case, time is of the essence so I'm using the second approach because it start the listener about 2 minutes faster than the first approach.

C# Socket: how to simulate real LDAP client connecting?

I have an error condition in my connection handling code. This error causes my server to freeze, but RANDOMLY, on some requests. It's important the requests are identical. Let's say 25% of them causes the server to freeze.
Here's the catch: the server freezes when and only when the first TEST request is made. On infinite number of subsequent TEST requests it won't fail... It's very important: it happens only when testing with my unit test.
My test just runs DirectoryEntry query. It creates n DirectoryEntry objects, queries them, then calls Close on each one, then repeats the procedure m times.
If it fails, it fails on first query.
BUT THEN if I connect real LDAP client like LdapAdmin, it behaves completely different! The chance the server will crash is very high, over 50%. Obviously, the real client does something differently while connecting, and obviously, even my C# test code also does that crashing thing, but only for the first time. My subsequent test queries do not test the server at all. They have zero efficiency against detecting "client connecting" freeze.
Now I test it by manually running my test "exe" file several times. Probability of catching the freeze is nearly 100% after 8 tries. Now I want my unit test to do that for me - do the offending action let's say 8 times and fail if it freezes once.
Unfortunately - the state of connecting client is different on application start and on subsequent calls. My question is WHAT EXACTLY is different? I tested it's not the server under the test. I can crash it anytime by connecting to it from external client. First attempt - success, client connected, client can try to DDOS my server, good luck, it doesn't happen. But then I try to connect again, server dies. I try to simulate this behavior in my test, but I fail. Either I detect crash on first attempt, or I get infinite number of successful connections. I need a way to truly reset my test client, so they would behave like a new client app connecting to my server for the first time. Close and Dispose methods of DirectoryEntry do not achieve that goal, or something else is involved.
No code sample, because DirectoryEntry query is a one-liner. My test should just execute such query, but should also disconnect afterwards forgetting it ever connected to the server. I want each DirectoryEntry query be as fresh and first as when the application is started.
BTW, I already found the cause of this particular freeze, now I want such case to be detectable by my unit test to avoid similar issues when the code is changed.
Another weird finding: When I try to connect 10k clients to my server - it passes... or fails on the first attempt.
Also tried:
I waited for Disposed event of DirectoryEntry objects. Didn't help. Still no joy. To catch the freeze I must run the same test several times.
Tried to dispose all objects including the tested server and recreate them multiple times during the test. Still no joy. Either fails on start, or doesn't fail no matter how many times this test is iterated.

SignalR Groups.Add times out and fails

I'm trying to add a member to a Group using SignalR 2.2. Every single time, I hit a 30 second timeout and get a "System.Threading.Tasks.TaskCanceledException: A task was canceled." error.
From a GroupSubscriptionController that I've written, I'm calling:
var hubContext = GlobalHost.ConnectionManager.GetHubContext<ProjectHub>();
await hubContext.Groups.Add(connectionId, groupName);
I've found this issue where people are periodically encountering this, but it happens to me every single time. I'm running the backend (ASP.NET 4.5) on one VS2015 launched localhost port, and the frontend (AngularJS SPA) on another VS 2015 launched localhost port.
I had gotten SignalR working to the point where messages were being broadcast to every connected client. It seemed so easy. Now, adding in the Groups part (so that people only get select messages from the server) has me pulling my hair out...
That task cancellation error could be being thrown because the connectionId can't be found in the SignalR registry of connected clients.
How are you getting this connectionId? You have multiple servers/ports going - is it possible that you're getting your wires crossed?
I know there is an accepted answer to this, but I came across this once for a different reason.
First off, do you know what Groups.Add does?
I had expected Groups.Add's task to complete almost immediately every time, but not so. Groups.Add returns a task that only completes, when the client (i.e. Javascript) acknowledges that it has been added to a group - this is useful for reconnecting so it can resubscribe to all its old groups. Note this acknowledgement is not visible to the developer code and nicely covered up for you.
The problem is that the client may not respond because they have disconnected (i.e. they've navigated to another page). This will mean that the await call will have to wait until the connection has disconnected (default timeout 30 seconds) before giving up by throwing a TaskCanceledException.
See http://www.asp.net/signalr/overview/guide-to-the-api/working-with-groups for more detail on groups

500 Internal Server Error With Ajax Request

hi guys,
Does anyone have any knowledge about the error seen at the image down below
The error occurs after waiting on the page for a while and then requesting an ajax call. The error is not repeated afterwards, but when the user waits again the error pops up again too. So the problem is about waiting on the page for a while, but could not find out why?
Thanks for the incoming responses
edit:link to image http://i53.tinypic.com/2ni8bcg.png
Well, basically an exception is occurring within your web service. It sounds like it's probably something timing out.
The first thing you should do is improve your logging (e.g. with ELMAH) so you can see exactly where the exception is being thrown... and then go about fixing it.
If it's a database connection timing out, it could be that you're forgetting to close the connection somewhere...

Sql Server 2005 - Time Out in Asp.net c#

I am using Asp.Net c# and Sql Server 2005. I am using Masterpage and content page. when i debug my code that time it's give error ::
Window Internet Explorer
SYS.WEBFORMS.PAGEREQUESTMANAGER TIMEOUTEXCEPTION: THE SERVER REQUEST TIMED OUT.
Any body please help me out ?
Thanks
It is an Ajax error - do you only get the error when debugging? If you want to increase this timeout then set the AsyncPostBackTimeout of your script manager to something large
You have an ajax request that's taking too long to complete. It would help if you can isolate the request and share what it's trying to do.
This happens if you sit there too long trying to step through your ajax request. Either increase the timeout or work faster.
Incidentally, I believe the timeout setting defaults to 90 seconds. See this for more information.
I don't see anything immediately obvious in that error message to suggest it's a SQL server request that's timing out rather than any other sort of "server request". However, if it is, stick a profiler on your SQL server to see which request is taking a long time - and find out whether it's just a query which needs speeding up, a deadlock, or something like that.
Another possibility is that it's the connection pool - if you're not closing your connections properly, you could be timing out waiting for them to be returned to the pool. If that's the case, you obviously won't see the request in the SQL profiler.

Categories