Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you specify some examples? #36

Closed
gekigek99 opened this issue Feb 6, 2021 · 10 comments
Closed

Could you specify some examples? #36

gekigek99 opened this issue Feb 6, 2021 · 10 comments

Comments

@gekigek99
Copy link

I see that there are tons of different functions and I really don't know where to start implementing a simple "hello world" connections between 2 peers

Thanks

@huin
Copy link
Owner

huin commented Feb 6, 2021

Did you see the examples in https://github.com/huin/goupnp/blob/master/example/example_test.go ?

As for examples that do something else, I'd have to refer to the UPnP docs for the specific device types.

@gekigek99
Copy link
Author

Yep I saw them... I just thought that having some sort of docs could help a lot

@huin
Copy link
Owner

huin commented Feb 12, 2021

Sorry for the delayed response. Could you be more specific about how the documentation could be improved/added? What problem you're trying to solve that's not being served?

https://pkg.go.dev/github.com/huin/goupnp contains the generated docs from this source, including the README.

One place that I know that the docs are lacking is that the packages under goupnp/dcps are pretty minimal (goupnp/dcps/internetgateway1 for example). Unfortunately that's source code generated from the XML UPnP specs, which don't themselves contain descriptive documentation.

Those generated docs themselves refer to the UPnP standards website (e.g for InternetGatewayDevice), which aren't the most readable docs, but I can't claim to have any better information or knowledge than those documents provide.

For context: I'm not a UPnP expert by any stretch, I just created this library for my own purposes once, ended up not needing it, but maintaining it from time to time as people have made contributions.

@gekigek99
Copy link
Author

Yea no worries! I just became interested in the UPnP protocol and wanted to learn how to use it (like, I still don't understand what's the difference between internetgateway1 and internetgateway2 ahahahah XD ) and your rep seems quite popular so I wanted to try it out...

What I meant for "example" is just some sort of "hello world" string sent from 1 PC to an other in LAN (or WAN) to demonstrate the communication between 2 machines. (like a client.go that when it's run on 2 PC in the same LAN, they automatically (or by just specifying the IP address) connect)

I know it's very basic and your code is capable of much more complex things but this could be a way for the thousands of people just like me that want to know something about UPnP connection... and only after that, study all the possible use cases.

whatever you decide to do, thanks for the consideration

p.s. I know that when you are into something everything seems easy, but for the eye of an outsider like me this is some really weird stuff XD

@huin
Copy link
Owner

huin commented Feb 13, 2021

Reading your example for wanting to send a string sent from one PC on a LAN to another on the same LAN, UPnP (and therefore goupnp) shouldn't be needed at all, you could do that using the facilities in the standard Go net library.

If you were wanting to talk between LANs without a server on the open Internet to relay between them (i.e peer-to-peer), you might need to use the internetgateway1 or internetgateway2 packages to open up port forwarding assignments on either (or both) LANs.

However, I would still refer back to the UPnP standards/specs/documentation. I would rather not repeat documentation that specifies what the UPnP stuff does (i.e the semantics of various method calls in this library).

Two things that might be worth amending the docs on for goupnp are:

  • Stronger emphasis on going to look at the UPnP standards docs. Maybe finding better links for them.
  • Explaining that the internetgateway1 and internetgateway2 packages implement clients for different versions of the standards, and that routers might implement only one or both of them - basically you might have to request client(s) from both packages and see what comes back.

What do you think of those changes?

TBH, this library is somewhat low level and could stand a lot of improvement. Most peoples' use cases would be better served by a higher level package which takes care of using this library to talk to the router, but presents a simpler interface to "just forward a port" and "get the external IP address".

@gekigek99
Copy link
Author

If you were wanting to talk between LANs without a server on the open Internet to relay between them (i.e peer-to-peer), you might need to use the internetgateway1 or internetgateway2 packages to open up port forwarding assignments on either (or both) LANs.

Oh yep i definitely meant a sort of peer to peer "hello world" example between 2 LANs...

However, I would still refer back to the UPnP standards/specs/documentation

my problem as a beginner is just that it's very difficult to have a simple working example for testing and learning step by step (I'm not asking you do write it for me, I just wanted to report a problem that I found... Probably this rep is too technical for me ahahah)

Stronger emphasis on going to look at the UPnP standards docs

yep this could be helpful, the ones linked are quite long and sooo in depth that it's difficult to have a glance at it

Explaining that the internetgateway1 and internetgateway2 packages

For me it would be very good, but I'm a beginner for this subject and maybe you want to make your rep for technicians...

TBH, this library is somewhat low level and could stand a lot of improvement. Most peoples' use cases would be better served by a higher level package which takes care of using this library to talk to the router, but presents a simpler interface to "just forward a port" and "get the external IP address".

yea you are probably right
do you know of any reps that have higher level functions?

huin added a commit that referenced this issue Feb 21, 2021
@huin
Copy link
Owner

huin commented Feb 21, 2021

Sorry for the delay, this stuff tends to wait until the weekend when I have some free time. I've written up https://github.com/huin/goupnp/blob/master/GUIDE.md - let me know if that's helpful :)

@huin
Copy link
Owner

huin commented Feb 21, 2021

And as for a higher level library, I don't know of any offhand.

That said, looking for what packages import internetgateway2, there seem to be quite a few: https://pkg.go.dev/github.com/huin/goupnp/dcps/internetgateway2?tab=importedby

Quite a lot seem to be crypto-currency related things, and I certainly can't vouch for anyone else's code, but a lot of them do see to provide a nat package that handles port forwarding, and might contain interesting code to look at.

@gekigek99
Copy link
Author

ok thank you a lot!

even thought I'm am still unable to make it work (it says multiple or no services found), now it's clearer

it seems that the example just checks if there is some upnp service on the LAN and if there is none it exits while I am trying to start the listening for other clients online so that they can then communicate...

anyway thanks for the help!

That said, looking for what packages import internetgateway2, there seem to be quite a few: https://pkg.go.dev/github.com/huin/goupnp/dcps/internetgateway2?tab=importedby

thanks for the link I'll take a look :)

@huin
Copy link
Owner

huin commented Feb 22, 2021

Yeah, the example is pretty limited, but hopefully it's a good starting point.

There's no clearly always-right answer for if there are multiple router devices on the network, it could be that a single router presents multiple devices and you could use any of them. So if there are multiple, experiment with printing the model name and IP address of each to work out what's going on.

If there are no devices, then either your router doesn't implement UPnP, or it's switched off. UPnP is often regarded as a potential security threat if left running, so it's not uncommon to want to switch it off.

Happy coding :)

@huin huin closed this as completed Feb 22, 2021
huin added a commit that referenced this issue Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants