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 Server

Client Server

Scheduled Pinned Locked Moved C#
1 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 have used the following code for the client server communication.The start() starts the server and calls the SenMessage() to send the message to the server.This method takes as input the port number of the server that has started. It works fine.Suppose i start 2 servers, then both servers are calling the SendMessage().In this case one server communicates properly.For the 2nd one it says that the existing connection is closed. I think that when the 2nd server starts it should call the sendMessage() with some time delay.I hope that it work then.But im not sure how to do it.Please help me with this.<pre>private void Start_Click(object sender, EventArgs e) { //int n; //label1.Text = "Enter the value of n:"; String n2, n1, n3, n4; n1 = lb4.Text; n2 = lb5.Text; n3 = lb6.Text; n4 = lb7.Text; ProcessStartInfo si1,si2,si3,si4; if (cb.Checked && lb4.Text!="") { si1 = new ProcessStartInfo(n1); proc = Process.Start(si1); proclist.Add(proc); String portno1 = n1.Substring(18, 5); listBox1.Items.Add(portno1); pno1=Convert.ToInt32(portno1); SendMessage(pno1); } if (cb1.Checked && lb5.Text!="") { n2 = lb5.Text; si2 = new ProcessStartInfo(n2); proc = Process.Start(si2); proclist.Add(proc); String portno2 = n2.Substring(18, 5); int pno2 = Convert.ToInt32(portno2); SendMessage(pno2); } } public void SendMessage(int portnumber) { try { UdpClient client = new UdpClient("127.0.0.1", portnumber); listBox2.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"), portnumber); int n = client.Send(data, data.Length); listBox2.Items.Add("Sent..."); listBox2.Items.Add("Message received from {0}:"); listBox2.Items.Add(ipep.ToString()); Byte[] received = new

    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