Solved

HttpWebRequest Open Connection

Posted on 2013-06-04
9
340 Views
Last Modified: 2013-06-05
I cannot imagine why this has been so hard for me.

I'm trying to post some XML to a site...which I can do and get the initial response

I then want to keep that connection open indefinately and simply accept whatever data comes at me and pass it along to SQL..

So far, I can connect...post my command...and get the initial response and send to SQL.

But I cannot get any subsequent data.

Does this need to be done with Threading?  Async?
I'm lost.
0
Comment
Question by:lrbrister
  • 5
  • 4
9 Comments
 
LVL 25

Expert Comment

by:Ron M
Comment Utility
I don't believe this is possible.

The web server gets a request, and returns a response.
To get more responses, you have to send more requests.

Curious to see other experts input on this.
0
 

Author Comment

by:lrbrister
Comment Utility
xuserx2000,

It seems to me that as long as I send an HTTP 1.1 command and keep the connection alive and also get chuncked data...that should do it.

Can someone let me know if my logic is flawed, and if so, why

and

What would another solution be?
0
 
LVL 25

Expert Comment

by:Ron M
Comment Utility
Possibly async client side java code, using ajax?
..that would be my best guess.
0
 

Author Comment

by:lrbrister
Comment Utility
xuserx2000P

Any links to a solution that you know of?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 25

Expert Comment

by:Ron M
Comment Utility
http://api.jquery.com/jQuery.ajax/


I still think this would be a "polling" solution though.  Seems to me the nature of a webserver is to get a url request and return a response.  A client browser renders elements when it gets a response.

Basically, you would be sending requests every "x" milliseconds to a webservice or page..from the client side java code on a timer, and processing the responses client side so the page doesn't have to be reloaded.  This would "appear" to be a continuous connection, though it actually isn't.

In a console or windows app, with a sockets connection, you could process data as it is being recieved..and leave the connection open.  But you're programming for a browser.. I just don't think it's possible, unless someone else can show me it is, that's my answer.
0
 

Author Comment

by:lrbrister
Comment Utility
xuserx200

Thanks.
This is being done in WinForms.

Do you have an example of a sockets connection to an outside source?
0
 
LVL 25

Accepted Solution

by:
Ron M earned 500 total points
Comment Utility
0
 

Author Closing Comment

by:lrbrister
Comment Utility
Just so I have a way in, I think I can get some kind of solution

Whether its a socket...or a "polling" solution.

Thanks
0
 
LVL 25

Expert Comment

by:Ron M
Comment Utility
Here's another snippet I found using the WebClient class.
Looks promising...
-------------------------------------------------------------------------------------
using (var client = new WebClient())
using (var reader = new StreamReader(client.OpenRead(uri), Encoding.UTF8, true))
{
    string line;
    while ((line = reader.ReadLine()) != null)
    {
        Console.WriteLine(line);
    }
}
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now