Click here to Skip to main content
Sign Up to vote bad
good
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:16
Edited 16 Feb '13 - 0:22


1 solution

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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,376
1 OriginalGriff 6,571
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid