Code Monkey home page Code Monkey logo

Comments (2)

rlebeau avatar rlebeau commented on August 22, 2024

DisconnectNotifyPeer() is intentionally empty at the TCP level. It is a virtual method, various protocol-specific descendants override it when they need to send messages to peers while closing connections. But there is nothing in the Telnet protocol to notify a peer about when closing the connection, which is why TIdTelnet does not override DisconnectNotifyPeer(). TIdTelnet overrides Disconnect() itself instead, to shut down its internal reading thread while closing the connection.

Typically, the only way that Connect() would think the socket is already connected after a Disconnect() is if there is unread data left behind in the IOHandler's InputBuffer. Even though the physical socket has been closed, Indy will still allow reads to succeed until the InputBuffer is exhausted. This is by design.

So, to make sure the connection is fully closed, try clearing the InputBufer before calling Connect() again, eg:

IdTelnet1.Disconnect;
if Assigned(IdTelnet1.IOHandler) then
  IdTelnet1.IOHandler.InputBuffer.Clear; // <-- ADD THIS
IdTelnet1.Connect;

from indy.

lzplzp001 avatar lzplzp001 commented on August 22, 2024

Thank you! According to the code you provided, it worked!

from indy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.