Advertisement

Linux and all

Started by February 22, 2005 06:20 AM
7 comments, last by gcs584 19 years, 11 months ago
Hello, I've been googling on the web to find tutorials for C++ on how to do networking with TCP and UDP in Linux (client and server-side). I havn't found any relevant sites worthy of checking out, so I want to ask you guys if you know how to do this or where I can look to do something like this. And (optional) can someone tell me how to look (just theoretically, you don't have to bother with the code, if necessary) for servers over a TCP network without broadcasting? That is, if you can. Thanks
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
Hi,

Here's some stuff that should get you going. Someone posted this stuff sometime before ( a few days ago). It should get you going with linux. I've just looked at it and there's a file called bgnet2.pdf (something like that). It'll get you started.

I'll let someone else answer the second part of your question [smile]

[EDIT:] Concering the second part of your question. Do you mean "broadcasting" over LAN. If LAN, you could just temporarily pop up a UDP socket and broadcast that way and then just connect using a TCP/IP socket and then close UDP socket. If you mean over the internet/WAN, you would have to look into a lobby server (this is kind of like counter-strike lobby where it lists all the games). You would host the lobby on a static-ip or the like where users could connect to to look up games. After that, you could provide them the IP address to connect to of another user to join a game. This is just an idea. Hopefully, someone else will chirp in. I'm slightly new to networking.

GCS584
Advertisement
Most of it isn't really platform specific. Beej's tutorial ([google]) is good. Also the references here and the Forum FAQ should help.
Quote:
Original post by Brandon N
Most of it isn't really platform specific. Beej's tutorial ([google]) is good. Also the references here and the Forum FAQ should help.


The file I recommended is from Beej's tutorial .

Later,

GCS584

[EDIT:] Last Attacker: I've just realized you're from South Africa....that makes two of us [blink]

[Edited by - gcs584 on February 22, 2005 7:12:11 AM]
Thanks for your replies.
So, what libs are going to be used when working in Linux?
Because Windows uses winsock.h .

Anyway, I just wanted to know if there was a way to check if (a) host(s) can be found over a network similar to broadcasting or multicasting with TCP. So TCP doesn't have such a way. But if I didn't know the server's IP address, how else can I use TCP to find such a server, except for pinging IP address from 1.1.1.1 to 255.255.255.255 or something.

Thanks again.
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
TCP does not support broadcasts. To find servers on a LAN, you must use UDP broadcasts. You will need to ioctl the socket appropriately to send broadcasts.

To find servers on the internet is more problematic. Obviously the internet does not support broadcasts.

Your best bet is to use a server-list server or "master" server, which holds a list of servers.

The servers themselves will announce themselves to the master server (by TCP, UDP or something like that). The clients will connect to the master server to receive a list of servers.

The client can then send a UDP or something to each server in the list to verify that it's reachable and measure the round-trip time from its location. Servers with sufficiently small latency which are up can then be displayed to the user to select one.

The list-server could use HTTP entirely for its communication, as it's not time-crticial. The only tricky bit is getting the IP address of a server if it's NAT'd (which will not be successful). The master server should therefore do a UDP probe of the servers to make sure they're really there, not NAT'd or firewalled etc (people WILL try to run them anyway).

The list-server should periodically probe known servers to make sure they're still there. Active servers should periodically re-advertise to tell the master server they're still there.

Servers going down should tell the master they're going offline so it can immediately de-list them.

Servers which want to be private should have a way of not informing the master server of their existence - indeed, it should de-list them if they tell it to.

Servers shouldn't send their own IP address (usually), the master server should try to determine it, and probe it with a UDP as necessary. This means an appropriately static NAT'd server will still be usable.

The master server could also be some sort of standard directory server, for instance LDAP or something. But it'd still need a custom agent to do the probes.

This is the sort of thing that most games do.

Mark
Advertisement
Ok. Thanks you guys for your input on Linux networking and especially the other question.
I really appreciate it.

EDIT : Cool, gcs584, how long have you been in the UK?

[Edited by - Last Attacker on February 23, 2005 12:05:01 AM]
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
Just a note -- the TNL library (www.opentnl.org) includes an example master server that lists internet servers and returns their addresses to querying clients and the Zap example game that shows off a full client/server networked game with client-side prediction, a networked physics model and more. Zap will broadcast over the LAN for game servers or query the master for internet servers. Both applications and the library build on linux.

- Mark
Quote:
Original post by Last Attacker
EDIT : Cool, gcs584, how long have you been in the UK?


Well, I was a Durban boy, but I moved to the 'States' for a while. I then moved to the UK in June of last year.

Glad I could help!

GCS584

This topic is closed to new replies.

Advertisement