Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 15-Feb-13 23:16pm
Edited 16-Feb-13 0:22am
v5

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try my article here : WCF Killer[^]
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100