anacrolix / utp

Use anacrolix/go-libutp instead
https://github.com/anacrolix/go-libutp
Mozilla Public License 2.0
173 stars 35 forks source link

net.Listener interface #20

Closed vtolstov closed 7 years ago

vtolstov commented 7 years ago

If i want to listen on utp packets, what i need to do? As i see package does not have Listen method, so i need to listen udp specific port and use NewSocketFromPacketConn? Does does it possible to create Listen method?

anacrolix commented 7 years ago

All the NewSocket* functions either listen, or take an already listening Conn. NewSocket is the utp package's Listen. The reason for the differing type is that a Socket is both a net.Listener, and a net.PacketConn.

Perhaps I should clear this up by improving the doc.

vtolstov commented 7 years ago

Thanks! But why not create Listen method, that run NewSocket and returns net.Listener interface?

anacrolix commented 7 years ago

That seems like a good compromise. Make a PR if you wish.

vtolstov commented 7 years ago

please check #21

vtolstov commented 7 years ago

Also note, why you hardcoded udp in all places and not create ability to specify udp4, udp, udp6 ? If i create pr, does it acceptable ?

anacrolix commented 7 years ago

I think because NewSocket is just a convenience, utp just wraps a net.PacketConn, so if you want full control, that's the way to go, with NewSocketFromPacketConn.