Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am c# novice and am writing server send multiple clients. i am able to send to single client however not able to multiple clients.
server code

namespace server2
{
    public partial class server2 : Form
    {
     List<tcpclient> _clients = new List<tcpclient>();
        _clients.Add(client1);
       _clients.Add(client2);

        public server2()
        {
            InitializeComponent();
        }

        private void server2_Load(object sender, EventArgs e)
        {
           byte[] bt;
           bt = new byte[] { 127,0,0,1 };
           IPAddress address = new IPAddress(bt);
    
           byte[] bt;
           bt = new byte[] { 127,0,1,1 };
           IPAddress address = new IPAddress(bt);         
        }


        private void send_Click(object sender, EventArgs e)
        {
            foreach (TcpClient client in _clients)
            {
                NetworkStream stream = client.GetStream();
                BinaryWriter bwrite = new BinaryWriter(stream);
                bwrite.Write(txtServer.Text);  
            }

        }

       
        private void add_Click(object sender, EventArgs e)
        {
            TcpClient client = new TcpClient();
            string ipAddress = txtClientAddress.Text;
            client.Connect(ipAddress, PORT);
            _clients.Add(client);
            txtClientAddress.Text = "";
            
        } 
         
        
  }
}


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 16-Feb-13 0:22am
v5

1 solution

Try my article here : WCF Killer[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900