LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-29-2008, 07:35 PM   #1
leedude
Member
 
Registered: Jan 2007
Location: Scotland
Distribution: Fedora, Debian
Posts: 81

Rep: Reputation: 15
Ports for game


hi, im planning to make an online game which will make use of TCP and UDP protocols.

what port should i use for the client/server communication?
What's stopping me from using...say...port 85?

Lee

Last edited by leedude; 08-29-2008 at 07:36 PM.
 
Old 08-29-2008, 07:39 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You must be root to use 1-1024. Other than that, your firewall might block connections from outside to other ports.
ta0kira
 
Old 08-29-2008, 07:51 PM   #3
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Aside from all ports to 1024 being usable only by root, Have a look at the IANA assigned ports. You can use any port not in the IANA list; however, anyone else can also use that port. You need to read your 'port' from a configuration file like most software does.

That is only for your 'listening' port though; all connections are dynamically assigned their own port when you accept() the connection (TCP). Obviously UDP works differently and if you don't always send to a fixed port, you will probably just lose most of the UDP packets.

Why use UDP at all? Due to the design of the internet, packets can arrive out of order, can be repeated, or simply lost (especially when you use UDP). There are libraries out there to handle these UDP issues (for example, RakNet), but if you are thinking of rewriting your own UDP code, give yourself a few months to work out most of the problems.
 
Old 08-30-2008, 04:56 AM   #4
leedude
Member
 
Registered: Jan 2007
Location: Scotland
Distribution: Fedora, Debian
Posts: 81

Original Poster
Rep: Reputation: 15
Thanks for replies.

i was going to use UDP for positional info(i believe it is faster than TCP).
the game itself is going to be a 2D multiplayer conflict game.

Quote:
You can use any port not in the IANA list
the following question springs to mind:
What if i use one in the list? internet police come and get me?

Lee.
 
Old 08-30-2008, 06:09 AM   #5
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Quote:
Originally Posted by leedude View Post
Thanks for replies.

i was going to use UDP for positional info(i believe it is faster than TCP).
the game itself is going to be a 2D multiplayer conflict game.


the following question springs to mind:
What if i use one in the list? internet police come and get me?

Lee.

Well, UDP is exactly as fast as TCP - there's no reason the signals will go down the wires any faster. TCP only goes funny when a message isn't delivered; it will retry the transmission a number of times with an increasing time interval between retries, and if you keep sending messages, the machine at the other end may suddenly see a packet storm when all the packets are delivered. Companies like Blizzard claim that TCP works fine for online games despite the odd retry-related glitch. If you really want to use UDP, have a look at RakNet - it manages reliable packet telemetry as well as 'normal' unreliable UDP packets. Maybe there are other alternatives around as well - when I looked into this in 2005 RakNet was the only one I could find.

Lucky for you there are no internet police. You can use absolutely any port you want on your own computers. The IANA list is there for interoperability - if you use a random port and ignore IANA assignments and you try to install another service later (like http) you may find that your new service can't open a port. And let's say you set up a corporate web page - but you used a different port for http - then only people who knew the secret (or used port sniffers) could connect to your website.

Last edited by pinniped; 08-30-2008 at 06:12 AM.
 
Old 08-30-2008, 07:12 AM   #6
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Why use UDP at all? Due to the design of the internet, packets can arrive out of order, can be repeated, or simply lost (especially when you use UDP).
This is not a problem for fast paced games, information such as position velocity if dropped by the network is fine as there will be another packet along soon which will give the newest and correct information, if an old packet is received it will be dropped by the network code as the information was time sensitive.

You really want to head over to gamedev.net specifically the network forum, here is some of the answers from the FAQ's.
Quote:
Q3) Should I use TCP or UDP?
A3) There are at least four different kinds of games as far as networking is concerned: Turn-based games, Real Time Strategy games, Role Playing Games, and Action Games. Briefly, if you're turn-based, you should go with TCP because it's simpler, unless you need peer-to-peer NAT punch-through. For RTS games, you're usually best off using TCP, although UDP can make sense in extreme cases. For role playing games, the story is less clear -- action-based RPGs with lots of kinetics, like City of Heroes, use UDP, whereas slower RPGs and MUDs often stay with TCP. For action-based games like first-person shooters or racers, you should absolutely use UDP.



Q4) If TCP makes sure the data gets to me without me needing to worry about it, why would I want to use UDP, which makes no such guarantees?
A4) TCP is a stream-based protocol. What goes in one end, will come out the other end, in order, with no duplication or packet drops. This is very convenient when correctness is paramount. However, to make this guarantee, TCP must suspend all packet delivery to the receiving end, if one packet is lost, until that packet can be detected as lost and re-sent. This may cause hick-ups of several seconds for a single packet that's lost!



Q5) Is UDP faster than TCP?
A5) UDP uses slightly smaller headers per packet than TCP, which may give you marginally better throughput on narrow channels (such as modems). UDP will also deliver any received packet as it is received, without waiting to re-order packets, so if latency is more important than correctness of the underlying channel, then UDP will introduce less jitter in your game, and gameplay will be smoother.

Last edited by dmail; 08-30-2008 at 07:17 AM.
 
Old 08-30-2008, 08:17 AM   #7
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Quote:
Originally Posted by dmail View Post
This is not a problem for fast paced games, information such as position velocity if dropped by the network is fine as there will be another packet along soon which will give the newest and correct information, if an old packet is received it will be dropped by the network code as the information was time sensitive.

You really want to head over to gamedev.net specifically the network forum, here is some of the answers from the FAQ's.
I'm familiar with all the issues - I'm just saying that games like Blizzard's WoW use TCP and Blizzard claims it's fine except for the occasional and rare glitch. Blizzard isn't the only company making these claims and selling MMORPGs that use TCP. The other point is that you do need to spend a lot of time to get UDP working for you; games will always need a guaranteed delivered packet as well as the non-guaranteed packet. To make UDP 'reliable' involves an awful lot of work.
 
Old 08-30-2008, 01:41 PM   #8
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
WOW uses TCP for one simple reason, the data is more important than speed.
Quote:
TCP ... is very convenient when correctness is paramount.
 
Old 08-30-2008, 01:44 PM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by leedude View Post
Thanks for replies.

i was going to use UDP for positional info(i believe it is faster than TCP).
the game itself is going to be a 2D multiplayer conflict game.
Lee.
Your strategy to use UDP for this is valid. If you are updating things rapidly, especially where the entire atom of data can be encapsulated in a single datagram, you don't necessarily car about a few dropped packets. Your most important information is likely be the most recent data only. For motion oriented data, that would mean you probably need to know where an object is now, and where is was at any time in the past is less important; maybe completely unimportant.
Other aspects of the data may require reliability, to ensure that completeness and order-of-events is maintained.
--- rod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
will you play windows game or linux native game pleasehelpme Linux - Newbie 16 04-29-2007 08:58 PM
How do you know what ports to use in a game? RHLinuxGUY Linux - Games 5 08-21-2006 11:41 AM
How to play java game(like yahoo game) in firefox? Mathsniper Debian 1 01-04-2006 10:00 AM
2D/3D Game EASY Game Development Software tedjordan Linux - Games 1 03-22-2005 06:40 AM
game not receving game list from master server Rnastyracer Linux - Games 2 04-02-2004 10:20 PM


All times are GMT -5. The time now is 09:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration