Jump to content
  • Advertisement
Sign in to follow this  
domok

Need some info to get started with network programming

This topic is 2781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

I'm programming in C++ and want to start network programming. I have found enet is really good, but then I saw that it doesn't support Mac and I really need it to be cross platform. So I'm looking for a network library (doesn't really matter if TCP or UDP), that is free and cross platform.

Or is it a very bad idea to do it on your own without a wrapper as it is in Beej's Guide to Network Programming? I won't be sending around huge packets and of course it has to be fast, but as there won't be many players this shouldn't be a problem.

And another question that must have been asked a 100 times but I couldn't find an answer: I can connect with enet to a server that runs on my on computer with 127.0.0.1 but how does this work with server on another computer (with firewall)?

Answer to FAQ: "To programmatically determine the CORRECT address to use, you have to bounce a query off a server that's available on the public internet, and look at what address it returns back. This will work correctly for situations where you're behind NAT (routers/firewalls)."

Could someone explain that to me....

Thanks for the info

Dominic

Share this post


Link to post
Share on other sites
Advertisement
I use SDL_Net, its free, open source and cross platform.

Quote:

And another question that must have been asked a 100 times but I couldn't find an answer: I can connect with enet to a server that runs on my on computer with 127.0.0.1 but how does this work with server on another computer (with firewall)?

127.0.0.1 also referred to as loop back interface or ipadress is a special ipadress that always resolves to your own computer.

So if you have a two computers (computer1 and computer2), running a server on computer1 on 127.0.0.1 at port 2000 while trying to connect from computer2 to 127.0.0.0 at port 2000 will result that computer2 only tries to connect to itself.

So if you want to run a server on a network, you must listen on an ipadress within the local network adress range.
If you are in windows, opening a command prompt and typing "ipconfig /all" will you lots of information about your current ipadress.

Quote:

Answer to FAQ: "To programmatically determine the CORRECT address to use, you have to bounce a query off a server that's available on the public internet, and look at what address it returns back. This will work correctly for situations where you're behind NAT (routers/firewalls)."

I guess this could refer to DNS (Domain Name System), for example if your program connects to "www.gamedev.net", the underlying DNS resolver (handled by the OS) will send a query the a DNS server to ask what ipadress is associated with the name "www.gamedev.net".

The name servers are often provided by your ISP (in most cases you will get your ipadress and name server information from your ISP DHCP server)
But there is nothing stoping you from using custom ones, such as http://www.opendns.com/.

Share this post


Link to post
Share on other sites
The OP asked for an open source / cross platform library:
Quote:

I have found enet is really good, but then I saw that it doesn't support Mac and I really need it to be cross platform. So I'm looking for a network library (doesn't really matter if TCP or UDP), that is free and cross platform.

I doubt winsock is any of those.

Share this post


Link to post
Share on other sites
Thanks flodihn

SDL_Net sounds good. But is it a good idea to use it without using SDL for graphics, sound etc?

And I know that 127.0.0.1 can't be used to connect to other computer but when I show the ipconfig my address is shown like 192.168.x.y and that isn't the right IP either. And when I use the IP that i get from http://www.ip-adress.com/ it doesn't work either. So how can I get the correct IP when I am behind NAT?

winsock is of course good and easy, but as I said I need it to be cross platform.

Or maybe someone knows: CAN ENET SOMEHOW WORK ON MAC or is that not possible at all??

Share this post


Link to post
Share on other sites
Quote:
Original post by domok
Or maybe someone knows: CAN ENET SOMEHOW WORK ON MAC or is that not possible at all??
I don't see why it wouldn't. Why don't you give it a try?

Share this post


Link to post
Share on other sites
Quote:
Original post by domok
I have found enet is really good, but then I saw that it doesn't support Mac and I really need it to be cross platform.
Wherever did you get that idea? Enet had always supported Mac.

It treats Mac as a 'unix-like operating system' in the manual, which is how Macs are treated by most cross-platform software.

Share this post


Link to post
Share on other sites
Quote:
Original post by domok
Thanks flodihn

SDL_Net sounds good. But is it a good idea to use it without using SDL for graphics, sound etc?

Yeah you can use SDL_Net without SDL for graphics, for example I use Ogre3d for graphics, OIS input for keyboard/mouse input, SDL_Mixer (for music), SDL_Net for networking and SDL for Joystick input.

Quote:
Original post by domok
And I know that 127.0.0.1 can't be used to connect to other computer but when I show the ipconfig my address is shown like 192.168.x.y and that isn't the right IP either. And when I use the IP that i get from http://www.ip-adress.com/ it doesn't work either. So how can I get the correct IP when I am behind NAT?

Are the computer you try to connect on the same local area network (beyond same NAT/router).

If they are you should be able to use 192.168.x.x, make sure any firewalls on the computers are not blocking you.
If you run your server on one of the computers on 192.168.1.10:2000 you should be able from the other computer start a command prompt and type "telnet 192.168.1.10 2000", if telnet just trying to connect forever a firewall on one of the computers is blocking you.

If you are running a server and want computers outside your NAT to connect, you start the server at 192.168.1.10:2000 for example, then you must tell your router to forward any traffic on port 2000 (or any arbitrary valid port number) to 192.168.1.10:2000.
Since most ISP changes your ipadress once and while, I recommend a dynamic dns server, for example dyndns.org.

Share this post


Link to post
Share on other sites
Then I'll propably stick with enet. I've just seen unix and windows on the enet page and so I thought it doesn't support mac...

When I connect to another computer on the same local area network it works with 192.168.x.y but I want to connect to any computer. You've written how to do that, but I don't really understand it. How can I tell the router to forward any traffic on port 2000? And I won't have a central server. The first player who starts the game will be the server and upload his ip somewhere on the internet, where the other players can download it. Is it possible this way? And how can it be done?

Thanks for all the answers

Share this post


Link to post
Share on other sites
Quote:
Original post by domok
Then I'll propably stick with enet. I've just seen unix and windows on the enet page and so I thought it doesn't support mac...
You do realize that OSX is based on UNIX?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!