(Sorry if i've grammar errors, i'm spanish)

Hi people!, I want to solve one question in my C# console project:

I want to close a TCPClient connection. When my program connect with the server, I can close this connection with the socket ( Server.Close(); ). When I try to reconnect (using the same method) I get to connect again my program to the server, but I don't receive data from it.

How can I reconnect my program? I've tried closing the socket...

Thanks in advance, pguti19.

Recommended Answers

All 2 Replies

hmm,could you please post some code so that we can see what s going on?

 public static void TMain()
            Console.WriteLine("[***]Connecting to: " + "" + "[***]");
            Server = new TcpClient("", 2001);
            ServerStream = Server.GetStream();

            sock = Server.Client;
            Console.WriteLine("[***]Connected from: " + sock.LocalEndPoint + "[***]");

            Console.WriteLine("Finsihed Connecting!");

            while (Server.Connected && Util.Continue)

                if (Server.Available > 0)

                    if (!Started)
                        Started = true;
                    byte[] Data = new byte[Server.Available];
                    ServerStream.Read(Data, 0, Server.Available);
                    string paquete = Encoding.Default.GetString(Data);
                    paquete = Encoding.Default.GetString(Encryption.Deciphe(Data, Data.Length));
                    byte[] newBuffer = Encoding.Default.GetBytes(paquete);

                    if (paquete.StartsWith("<"))
                        //Show Policy
                        Util.ConsoleWriteLineFilter("[RCV] -> " + paquete);
                        //Show Packet


            Checker = null;

When it reconnects, don't receive data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.