0

I have a List of Sockets that are connected and live on the Form1

List<Socket> Clients;

For Example i want to Pass on of the Socket to the next Forms as:

Form2 F2 = new Form2();
F2.ClientSocket = Clients[2];

So I want to Close the Socket :

Clients[2]

and let the F2.ClientSocket Opened just like we're passing the connection from socket to socket !

Thanks for your Time !

6
  • I was following you until you started talking about closing the socket at which point you totally lost me. Can you explain more about what you're trying to do? Commented Aug 2, 2016 at 21:21
  • I want to pass the Connection between the server and the client From the socket (Clients[2]) to the next socket F2.ClientSocket Commented Aug 2, 2016 at 21:22
  • 1) No idea what "pass the connection" means. The socket represents the connection. 2) You just set F2.ClientSocket to Clients[2] so how could it be the next socket? Commented Aug 2, 2016 at 21:26
  • Lets say a Data has been sent to the Server on the Socket Clients[2] This data Will be sent on the Both Sockets For example we have a methode of check if the sent data was "Test" Show a Messagebox the Messagebox will be shown twice Cause there were 2 Sockets i want the Socket Clients[2] to shutdown and let the connection between the server and that client on the Socket F2.ClientSocket Commented Aug 2, 2016 at 21:29
  • 1
    You can't do that because Clients[2] and F2.ClientSocket refer to the same object. If you shutdown one you shutdown the other too. Just don't read from Clients[2] once you pass it off. Or remove it from the list entirely since you really don't need it anymore. Commented Aug 2, 2016 at 21:32

1 Answer 1

1

use static objects:

Form1:

class Form1
{
    public static List<Socket> clients = new List<Socket>();
    // your codes
}

Form2:

class Form2
{
    public Form2
    {
        var client =  Form1.clients[index];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.