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. Client in C#

Client in C#

Scheduled Pinned Locked Moved C#
csharpxml
2 Posts 1 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.
  • M Offline
    M Offline
    mrithula8
    wrote on last edited by
    #1

    Hi, I am using the following code to read the port number from xml file and send as a parameter to UdpClient.It works well. p1.xml file is stored in C:\projects\ports\10000...Simliarly i have stored p2.xml file in C:\projects\ports\10001 folder.p2.xml contains the port number 10001. When the client clicks the C:\projects\ports\10000 path the exe in this path opens and communicates with the client by accepting the port 10000 from p1.xml.I am done with this step. Suppose if the client clicks C:\projects\ports\10001 the exe opens .But now it should now accept the port as 10001 from p2.xml and do the communication with the client.Likewise for other ports also. Please give me your ideas.

    XmlTextReader xt = new XmlTextReader("p1.xml");
    int p1=0;
    while (xt.Read())
    {
    switch (xt.NodeType)
    {
    case XmlNodeType.Text:

                            String rv = xt.Value;
                            p1 = Convert.ToInt32(rv);
                            break;
                    }
                }
    
                listBox6.Items.Add("Connecting....");
                UdpClient client = new UdpClient("127.0.0.1",p1);
    
    M 1 Reply Last reply
    0
    • M mrithula8

      Hi, I am using the following code to read the port number from xml file and send as a parameter to UdpClient.It works well. p1.xml file is stored in C:\projects\ports\10000...Simliarly i have stored p2.xml file in C:\projects\ports\10001 folder.p2.xml contains the port number 10001. When the client clicks the C:\projects\ports\10000 path the exe in this path opens and communicates with the client by accepting the port 10000 from p1.xml.I am done with this step. Suppose if the client clicks C:\projects\ports\10001 the exe opens .But now it should now accept the port as 10001 from p2.xml and do the communication with the client.Likewise for other ports also. Please give me your ideas.

      XmlTextReader xt = new XmlTextReader("p1.xml");
      int p1=0;
      while (xt.Read())
      {
      switch (xt.NodeType)
      {
      case XmlNodeType.Text:

                              String rv = xt.Value;
                              p1 = Convert.ToInt32(rv);
                              break;
                      }
                  }
      
                  listBox6.Items.Add("Connecting....");
                  UdpClient client = new UdpClient("127.0.0.1",p1);
      
      M Offline
      M Offline
      mrithula8
      wrote on last edited by
      #2

      Hi I had a try with array of the port values. I have used an index that maps the directories to ports.I am stuck at a point.Since i am using the for loop it works well for i=0. i=1 should not execute before the server at C:\projects\ports\10001 starts.How can change this?Is there any loop construct that could help me perform this task?i should get incremented and do the same after the 2nd server starts.Can you please give your suggestions.I tried with break but still im not getting it right.

      int[] a = new int[2];
      XmlTextReader xtr1 = new XmlTextReader("p1.xml");
      XmlTextReader xtr2 = new XmlTextReader("p2.xml");
      int p1=0,p2=0;
      while (xtr1.Read())
      {
      switch (xtr1.NodeType)
      {
      case XmlNodeType.Text:

                              String rv = xtr1.Value;
                              p1 = Convert.ToInt32(rv);
                              break;
                      }
                  }
      
                  while (xtr2.Read())
                  {
                      switch (xtr2.NodeType)
                      {
                          case XmlNodeType.Text:
      
                              String rv1 = xtr2.Value;
                              p2 = Convert.ToInt32(rv1);
                              break;
                      }
                  }
                  a\[0\] = p1;
                  a\[1\] = p2;
      
                  listBox6.Items.Add("Connecting....");
                  for (int i = 0; i <= 1; i++)
                  {
                      UdpClient client = new UdpClient("127.0.0.1", a\[i\]);
      
                      listBox6.Items.Add("Connected");
                      Byte\[\] data = new Byte\[256\];
                      String snd = "hello";
                      data = Encoding.ASCII.GetBytes(snd);
                      IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), a\[i\]);
                      int n = client.Send(data, data.Length);
                      listBox6.Items.Add("Sent...");
                      listBox6.Items.Add("Message received from {0}:");
                      listBox6.Items.Add(ipep.ToString());
                      Byte\[\] received = new Byte\[512\];
                      received = client.Receive(ref ipep);
                      String dataReceived = System.Text.Encoding.ASCII.GetString(received);
                      listBox6.Items.Add(dataReceived);
      
      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