Comments (6)
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.
@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.
@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.
@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.
@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.
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)
- How to Read data unblock? HOT 1
- how to set timeout for client? HOT 1
- Server response log
- Log IPs that connect to the telnet server
- how to get client terminal size?
- can support Cluster address?
- Is there a ReadString ('\ n')? HOT 2
- TELNET Shell Server Example build error HOT 6
- Client hangs for a minute at first. HOT 1
- Not only connecting Telnet Server port, connecting other ports
- Redundant c.Close()
- telsh command with arguments
- sample script HOT 2
- How can the server detect conn is closed? HOT 1
- A bit of help
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-telnet.