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. how to create multiple connections in a client application

how to create multiple connections in a client application

Scheduled Pinned Locked Moved C#
helptutorial
6 Posts 3 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.
  • A Offline
    A Offline
    Ajithevn
    wrote on last edited by
    #1

    i have a client application i which i need to connect to the remote machine on click of a button and localhost on every minute.is it possible. plz help me.

    B A 2 Replies Last reply
    0
    • A Ajithevn

      i have a client application i which i need to connect to the remote machine on click of a button and localhost on every minute.is it possible. plz help me.

      B Offline
      B Offline
      Bjorn T J M Spruit
      wrote on last edited by
      #2

      Can you be more specific as to how you want to connect to a machine ? Is it a database connection you wish to establish ?

      A 1 Reply Last reply
      0
      • A Ajithevn

        i have a client application i which i need to connect to the remote machine on click of a button and localhost on every minute.is it possible. plz help me.

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #3

        Yes.. On every client request create a new thread and run the task in its own thread until it returns to its tread pool. Just like what IIS does for every requests. :)

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Microsoft Bing MAP using Javascript
        CLR objects in SQL Server 2005
        Uncommon C# Keywords
        /xml>

        A 2 Replies Last reply
        0
        • B Bjorn T J M Spruit

          Can you be more specific as to how you want to connect to a machine ? Is it a database connection you wish to establish ?

          A Offline
          A Offline
          Ajithevn
          wrote on last edited by
          #4

          Bjorn Spruit wrote:

          Is it a database connection you wish to establish ?

          No its not a database connection. it is a socket connection between the client and the server of the remote machine

          1 Reply Last reply
          0
          • A Abhishek Sur

            Yes.. On every client request create a new thread and run the task in its own thread until it returns to its tread pool. Just like what IIS does for every requests. :)

            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


            My Latest Articles-->** Microsoft Bing MAP using Javascript
            CLR objects in SQL Server 2005
            Uncommon C# Keywords
            /xml>

            A Offline
            A Offline
            Ajithevn
            wrote on last edited by
            #5

            can u be more specific im not getting any idea about it. you mean to say when client send or recieve a msg run a new thread and reconnect to the server

            1 Reply Last reply
            0
            • A Abhishek Sur

              Yes.. On every client request create a new thread and run the task in its own thread until it returns to its tread pool. Just like what IIS does for every requests. :)

              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


              My Latest Articles-->** Microsoft Bing MAP using Javascript
              CLR objects in SQL Server 2005
              Uncommon C# Keywords
              /xml>

              A Offline
              A Offline
              Ajithevn
              wrote on last edited by
              #6

              i have tried running threads in this format. but this also works only if button is clicked and only for 4 times but i wish 1 client to connect to the server when button is clicked and other client will connect and close for each minute. the code is:-

              private void button1_Click(object sender, EventArgs e)
              {
              for (int i = 0; i < 4; i++)
              {
              Thread thread = new Thread(new ParameterizedThreadStart(round));
              thread.Start();
              thread.Join();
              Thread.Sleep(100);
              }
              }
              private void round(object val)
              {
              System.Net.IPAddress myIP;
              System.Net.IPEndPoint myServer;
              Socket socket;
              string ip = (string)val;

                      try
                      {
                          myIP = System.Net.IPAddress.Parse(ip);
                          myServer = new System.Net.IPEndPoint(myIP, Int32.Parse("20000"));
                          socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream ,ProtocolType.Tcp);
                          socket.Connect(myServer);
                          NetworkStream netStream=new NetworkStream(socket);
                          Byte\[\] byteMessage=new Byte\[640\];
                          string sendMessage="hello server";
                          byteMessage=System.Text.Encoding.Default.GetBytes( sendMessage.ToCharArray());
                          netStream.Write(byteMessage,0,byteMessage.Length);
                          netStream.Flush();
                          netStream.Close();
                          socket.Close();
                      }
                      catch (Exception ee)
                      {
                          MessageBox.Show(ee.Message);
                      }
                  }
              
              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