Giter Site home page Giter Site logo

Comments (6)

majgis avatar majgis commented on July 26, 2024 1

I did an experiment modifying these two files:

modified:   vendor/github.com/reiver/go-telnet/context.go
modified:   vendor/github.com/reiver/go-telnet/server.go

I allowed for the setting of nett.Conn on telnet.Context, and set it inside server.go.
In response to your query, net.Conn.RemoteAddr() Addr is my primary concern in identifying which connection the command handler was triggered by. In the changes I proposed in #7 I'm needing the same information from net.Conn.RemoteAddr() Addr, but it makes more sense to include a reference to the connection rather than extract a single value.

If you are interested, I'll do a PR with what I've described, which should allow closing #6 and #7, after shipping what I'm currently working on.

from go-telnet.

reiver avatar reiver commented on July 26, 2024

@diltram I tried to make my telnet package feel like Go's built-in "net/http" package.

Thus, my telnet.Server struct is meant to feel like the http.Server struct.

The telnet.Server struct (and the http.Server struct) don't represent the underlying TCP connection(s).

It is the (non-exported) telnet.Server.handle() method that has access to the TCP connection.

(Well, that and the telnet.Server.Serve() method, that calls telnet.Server.handle().)

from go-telnet.

reiver avatar reiver commented on July 26, 2024

@diltram Why do you want access to the underlying TCP connection?

What are you trying to do?

(If I understood what you are trying to accomplish, it might make it easier to figure out how to best design this.)

from go-telnet.

reiver avatar reiver commented on July 26, 2024

@diltram Actually... the Go built-in "net/http" package lets you access the underlying TCP connection with http.Hijacker

Could implement something similar to that for my telnet package.

It would make it so my telnet package still feels like "net/http".

from go-telnet.

reiver avatar reiver commented on July 26, 2024

@diltram So, what I'm thinking is something like this:

func myServeTELNET(ctx telnet.Context, w telnet.Writer, r telnet.Reader) {

    hj, ok := w.(telnet.Hijacker)
    if !ok {
        io.WriteString(w, "TELNET server doesn't support hijacking\r\n")
        return
    }

    conn, err := hj.Hijack()
    if nil != err {
        io.WriteString("ERROR: ")
        io.WriteString(w, err.Error())
        io.WriteString("\r\n")
        return
    }

    //@TODO: Do something with the net.Conn
}

But... me understanding why you want to get access to the underlying net.Conn (rather than just using telnet.Writer and telnet.Reader) could suggest that maybe telnet.Writer or telnet.Reader (for example) need more methods.

So... what did you need to use from net.Conn?...

  • net.Conn.LocalAddr() Addr
  • net.Conn.RemoteAddr() Addr
  • net.Conn.SetDeadline(t time.Time) error
  • net.Conn.SetReadDeadline(t time.Time) error
  • net.Conn.SetWriteDeadline(t time.Time) error

from go-telnet.

sebastien-rosset avatar sebastien-rosset commented on July 26, 2024

One use case would be to gracefully notify clients that connections are going to be closed.
Golang net.http.Server supports Shutdown() and Close() to terminate connections.

from go-telnet.

Related Issues (16)

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.