Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. HttpWebRequest simultaneously!!!!

HttpWebRequest simultaneously!!!!

Scheduled Pinned Locked Moved C#
databasesysadminalgorithmshelpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian_V_V
    wrote on last edited by
    #1

    HI... I managed searching in google to make a call to a server which returns me data from different GPS devices so I can save to a database. The problem is that I need to do the same but in two different server at the same time, ie, I need to get data from two different URL and save them in my database. This is what I achieved. try { byte[] buf = new byte[8192]; HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://xxx.xxx.xxx.xxx:7778/online?user=xx&pass=xxx"); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); Stream resStream = response.GetResponseStream(); //int count = 0; //string tempString = ""; Thread t = new Thread(delegate() { Go(buf, resStream, listaRelojes); }); // No need to explicitly use ThreadStart t.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } public void Go(byte[] buf, Stream resStream, LinkedList<reloj> listaRelojes) { int count = 0; string tempString = ""; tempString = Encoding.ASCII.GetString(buf, 0, count); do { count = resStream.Read(buf, 0, buf.Length); if (count != 0) { tempString = Encoding.ASCII.GetString(buf, 0, count); Parse(tempString, listaRelojes); System.Console.Out.WriteLine("my System: " + tempString); } } while (count > 0); } I need something like this I think : WebRequest.Create("http://xxx.xxx.xxx.xxx:7778/online?user=xx&amp;pass=xxx"); and WebRequest.Create("http://yyy.yyy.yyy.yyy:7779/online?user=yy&amp;pass=yyy"); at the same time. Is this posible??? Thank´s in advance. Christian...

    L J M 3 Replies Last reply
    0
    • C Christian_V_V

      HI... I managed searching in google to make a call to a server which returns me data from different GPS devices so I can save to a database. The problem is that I need to do the same but in two different server at the same time, ie, I need to get data from two different URL and save them in my database. This is what I achieved. try { byte[] buf = new byte[8192]; HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://xxx.xxx.xxx.xxx:7778/online?user=xx&pass=xxx"); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); Stream resStream = response.GetResponseStream(); //int count = 0; //string tempString = ""; Thread t = new Thread(delegate() { Go(buf, resStream, listaRelojes); }); // No need to explicitly use ThreadStart t.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } public void Go(byte[] buf, Stream resStream, LinkedList<reloj> listaRelojes) { int count = 0; string tempString = ""; tempString = Encoding.ASCII.GetString(buf, 0, count); do { count = resStream.Read(buf, 0, buf.Length); if (count != 0) { tempString = Encoding.ASCII.GetString(buf, 0, count); Parse(tempString, listaRelojes); System.Console.Out.WriteLine("my System: " + tempString); } } while (count > 0); } I need something like this I think : WebRequest.Create("http://xxx.xxx.xxx.xxx:7778/online?user=xx&amp;pass=xxx"); and WebRequest.Create("http://yyy.yyy.yyy.yyy:7779/online?user=yy&amp;pass=yyy"); at the same time. Is this posible??? Thank´s in advance. Christian...

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      If you can open up two different browser instances, and successfully issue those URL requests in each of them simultaneously, I see no reason why two WebRequests wouldn't work equally well. However, I never did anything of that kind. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read formatted code with indentation, so please use PRE tags for code snippets.


      I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


      1 Reply Last reply
      0
      • C Christian_V_V

        HI... I managed searching in google to make a call to a server which returns me data from different GPS devices so I can save to a database. The problem is that I need to do the same but in two different server at the same time, ie, I need to get data from two different URL and save them in my database. This is what I achieved. try { byte[] buf = new byte[8192]; HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://xxx.xxx.xxx.xxx:7778/online?user=xx&pass=xxx"); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); Stream resStream = response.GetResponseStream(); //int count = 0; //string tempString = ""; Thread t = new Thread(delegate() { Go(buf, resStream, listaRelojes); }); // No need to explicitly use ThreadStart t.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } public void Go(byte[] buf, Stream resStream, LinkedList<reloj> listaRelojes) { int count = 0; string tempString = ""; tempString = Encoding.ASCII.GetString(buf, 0, count); do { count = resStream.Read(buf, 0, buf.Length); if (count != 0) { tempString = Encoding.ASCII.GetString(buf, 0, count); Parse(tempString, listaRelojes); System.Console.Out.WriteLine("my System: " + tempString); } } while (count > 0); } I need something like this I think : WebRequest.Create("http://xxx.xxx.xxx.xxx:7778/online?user=xx&amp;pass=xxx"); and WebRequest.Create("http://yyy.yyy.yyy.yyy:7779/online?user=yy&amp;pass=yyy"); at the same time. Is this posible??? Thank´s in advance. Christian...

        J Offline
        J Offline
        Jens Meyer
        wrote on last edited by
        #3

        Try threading with BackgroundWorker, Threads or CCR. I have done it myself on a recent project using CCR. But at first instance i suggest you give the BackgroundWorkers a shot. Regards Jens

        When in trouble, when in doubt, run in circles, scream and shout

        1 Reply Last reply
        0
        • C Christian_V_V

          HI... I managed searching in google to make a call to a server which returns me data from different GPS devices so I can save to a database. The problem is that I need to do the same but in two different server at the same time, ie, I need to get data from two different URL and save them in my database. This is what I achieved. try { byte[] buf = new byte[8192]; HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://xxx.xxx.xxx.xxx:7778/online?user=xx&pass=xxx"); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); Stream resStream = response.GetResponseStream(); //int count = 0; //string tempString = ""; Thread t = new Thread(delegate() { Go(buf, resStream, listaRelojes); }); // No need to explicitly use ThreadStart t.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } public void Go(byte[] buf, Stream resStream, LinkedList<reloj> listaRelojes) { int count = 0; string tempString = ""; tempString = Encoding.ASCII.GetString(buf, 0, count); do { count = resStream.Read(buf, 0, buf.Length); if (count != 0) { tempString = Encoding.ASCII.GetString(buf, 0, count); Parse(tempString, listaRelojes); System.Console.Out.WriteLine("my System: " + tempString); } } while (count > 0); } I need something like this I think : WebRequest.Create("http://xxx.xxx.xxx.xxx:7778/online?user=xx&amp;pass=xxx"); and WebRequest.Create("http://yyy.yyy.yyy.yyy:7779/online?user=yy&amp;pass=yyy"); at the same time. Is this posible??? Thank´s in advance. Christian...

          M Offline
          M Offline
          Martin Jarvis
          wrote on last edited by
          #4

          You can create the two requests as you like and then call BeginGetResponse() on each of them (MSDN Reference[^]). This will probably be the easiest way to get what you want without getting entangled with thread pools (and possible starvation).


          Freestyle Interactive Ltd | Martin on .Net

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups