(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: " + "217.13.120.201" + "[***]");
            Server = new TcpClient("217.13.120.207", 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)
                    {
                        Checker.Start();
                        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);
                        Thread.Sleep(5000);
                    }
                    else
                    {
                        //Show Packet
                        Type.Server.Hand(newBuffer);
                    }



                }
                Thread.Sleep(1);
            }

            Checker.Abort();
            Checker = null;
            Server.Close();
        }

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, networking, learning, and sharing knowledge.