cruny cruny - 1 month ago 24
C# Question

c# Pass Socket Connection

I have a List of sockets

List<Socket> Clients;

Client[index]
is receiving Data in a UI Form works perfectly , but i want to pass that socket to another Form2 so :

public Form2(Socket Client)
{

InitializeComponent();
this._Client = Client;
}


in my Form1:

Form2 f2 = new Form2(this.Clients[0]);
f2.Show();


My issue is i don't receive from the New socket i still receive from socket on Form1 !
i m confused how can i receive from the new socket !

Answer

There should only be one that will receive data from the socket. You should pass the data instead of the socket.

public class Form2 : Form
{
    public void HandleData(byte[] data)
    {

    }
}