TCP? UDP?

Blitz3D Forums/Blitz3D Beginners Area/TCP? UDP?

Buggy(Posted 2006) [#1]
Is it better - for an online game - to use UDP, TCP, or that QuickPlay or whatever thing there is? I've heard that WoW is in TCP, which doesn't seem possible with so many players... feedback, anyone?


LineOf7s(Posted 2006) [#2]
Short answer: UDP

Long(er) answer: Both [edit] (TCP and UDP) [/edit]


Buggy(Posted 2006) [#3]
Both what?


Naughty Alien(Posted 2006) [#4]
UDP is faster than TCP..so go with UDP..


Matty(Posted 2006) [#5]
For things like 'lobby' areas TCP is fine, for most messages in the actual 'game' area UDP.


Baystep Productions(Posted 2006) [#6]
I don't really notice a difference but find it easier to use TCP


LineOf7s(Posted 2006) [#7]
It's not about 'faster' or not, as such...

TCP is inherently 'reliable' - it guarantees to deliver every packet it sends, and in the order they are sent. If it needs to hold your game up for a few seconds while it repeatedly sends lost packets, then by God it will. This may not be desirable in a fast-paced sorta game.

UDP does the same sorta thing, but it couldn't care less whether the packets actually get there or not. It also doesn't care whether or not they get there in the right order. It just sends them - that's it. If you need to make sure at least some get there, or whatever, you need to code that sorta stuff yourself.

Now none or all of this may or may not matter. If you're doing an online game of poker, or Monopoly, or chess, or some sorta turn-based strategy game or something, then a few extra seconds waiting for a TCP/IP packet to get there won't be the end of the world. People probably won't even notice. Have your game client pause for a few seconds during a multiplayer FPS tournament though and you might get some nasty feedback from your customers.

Typically (and I'm no authority), people tend to use 'reliable' messaging (whether that be TCP/IP or coding your own reliable UDP system) for super-important but not time-critical things (like initialising the game, or repawning someone, or moving between levels etc), and use 'unreliable' UDP for most of the guts of the game, with the occasional 'reliable' message just to pull things back into line in case the 'unreliable' stuff has let things go off the rails a bit.

Of course, if you just wanna get things done without having to learn all this stuff (to the nth degree, anyway), then you could go for a solution like BlitzPlay. There's a Lite version for free so you can work out if it does what you want it to do. There's also RottNet in the code archives, which is a similar concept and is totally free (although arguably less mature).

Have fun!


Buggy(Posted 2006) [#8]
Then if speed is such an issue, why does WoW use TCP? That would mean that if just one person has a slow connection, the whole server is slow! How does that work?


Dreamora(Posted 2006) [#9]
The server does not wait, thats multithreaded.
WoW is an MMO, thats not fast paced ... If you can afford latency of 200+, then TCP is the better choice as you're interpolation routines can be far stupider.

On the other side, WC3 for example is UDP.


Naughty Alien(Posted 2006) [#10]
..TCP is fine, but my experiance telling me that UDP is the way to go...but its up to you guys anyway..


Buggy(Posted 2006) [#11]
I tried a simple TCP program, but something always goes wrong... do I have to do OpenTCPStream each loop?

Here's the server code:

game = CreateTCPServer(500)

If game <> 0

	Print "Server Started"
	
Else

	Print "An Error Has Occurred"
	
	WaitKey
	
	End
	
EndIf

While Not KeyDown(1)

	stream = AcceptTCPStream(game)
	
	If stream Then
	
		Print "Connection Established"
		
		Print "Message: " + ReadString$(stream)
		
		Delay 1000
		
	Else
	
		Print "No Connection"
		
		Delay 1000
		
	EndIf
	
Wend


...and here's the client-ish code (remember, I'm new at this)

game = OpenTCPStream("127.0.0.1", 500)

If game <> 0

	Print "Connection!"
	
Else

	Print "Error!"
	
EndIf

While Not KeyDown(1)
	
	WriteString(game, n)
	
	WriteString(game, "Howdy!")
	
	n = n + 1
	
	Print n
	
	
	
Wend


End


Any help?


Buggy(Posted 2006) [#12]
If OpenTCPStream only works for one message, then what's the point of CloseTCPStream? I think I'm doing something wrong...

One more question... in OpenTCPStream and CreateServer, what do the 500 and the "127.0.0.1" mean? The second one should be an IP address, but I got it off of a tutorial, so I don't see how it could "know" my IP... and the 500 I completely made up!


Buggy(Posted 2006) [#13]
OK, so I've figured out that the 500 is interchangeable, and the 127.0.0.1 isn't... but what do they mean?

And why is it that if I add an OpenTCPStream command before every WriteString command (I took out the "Howdy!" writestring, see above), the variable n gets to about 4 or 5 and then an error says, "Stream does not exist!"

Can someone kindly shove me in the right direction (a mere nudge won't do it)? Thanks.


LineOf7s(Posted 2006) [#14]
No time to read through your code, but I can tell you one thing:

127.0.0.1 (aka localhost) is the IP address of the machine you're running the program on, no matter what it is.

Check out RottNett in the Code Archives and run through the syntax function by function. There's also an online multiplayer deathmatch thing there too, written using RottNett - both of these will together lead you well and truly down the path of enlightenment.


Buggy(Posted 2006) [#15]
But I want to try to actually understand and create my own code!


LineOf7s(Posted 2006) [#16]
So you see how someone else gets it to work, understand the basic concepts (knowing that they work), and adapt them to your own needs.

Y'know? Like people do.

Anything anyone tells you here will be a subset of what someone's already implemented in Blitz syntax specifically for people like yourself to learn from.

If you want to start totally from scratch for some reason, then you'll have to hunt down a bunch of internet networking tutorials on the web and adapt them to be used in Blitz. In that case, Google is your friend.

Either way, you're going to have to do some work.


Ross C(Posted 2006) [#17]
A good programmer uses the tools available ;o) Not code his own. It depends though. I used a netlib. RottNet. It works great and you gain an understanding of whats happening by using it. BUT, you don't need to know the nitty gritty of it. Isn't that what Blitz3D is about? ;o)


LineOf7s(Posted 2006) [#18]
I've always been of the mind that if I'm keen enough to just 'get on with it' such that I'm using Blitz instead of learning (say) C, then I'm keen enough to just 'get on with it' enough to use the helpful bits of stuff other people very kindly allow me to - whether that be networking libraries, map editors or whatever.

If I do something so comprehensive I exceed the capabilities of the already-done stuff, *then* I'll look to extend it and/or start again from scratch...

So yes Ross, I agree with you. :o)


octothorpe(Posted 2006) [#19]
Can someone kindly shove me in the right direction (a mere nudge won't do it)? Thanks.


Because your server hangs up after 1000 milliseconds?

After verifying that AcceptTCPStream succeeded, your server should loop until you're ready to disconnect.


Buggy(Posted 2006) [#20]
Sorry.. I didn't mean to anger or offend anyone here... ;)

I just want to understand how it works and what it's doing. Anyway, can someone try out my code and see why it doesn't work?


Buggy(Posted 2006) [#21]
It seems that the command CloseTCPServer doesn't work correctly, and possibly some of the other TCP commands, too. Is there an update for this?


Buggy(Posted 2006) [#22]
Will anyone answer me?


Farflame(Posted 2006) [#23]
Haven't read this through thoroughly, but I'm working on a multi-player game and I'm using the Raknet library, and I would strongly recommend it. It uses UDP but has all the functionality of TCP if you require it. So it's fast but if you WANT it to wait for a message to arrive, or you WANT it to send packets in order, then you can ask it to do so. For those packets, it will be slightly slower. For the ones which don't need this kind of checking, it runs very quickly and I haven't encountered any bugs or problems with it.


Wings(Posted 2006) [#24]
;For things like 'lobby' areas TCP is fine, for most messages in the actual 'game' area UDP.

cold be not be more wrong. UDP is good for searching for servers.. cause of the time out.. thats why udp is good for file sharing.. after a client finds server it will connect with tcp.

(like pc anywhere)


Buggy(Posted 2006) [#25]
I just can't seem to get TCP to work... there's always something that goes wrong!


Farflame(Posted 2006) [#26]
Seriously, try Raknet. Since it's a wrapper, it does most of the hard work for you. All you need to do is to learn the syntax and the basic concepts, after that it's just a case of 'connect', 'send packet' and so on. It has commands for disconnecting players, automatically checking connections, banning IP's.... all the usual stuff.


Wings(Posted 2006) [#27]
here is a working tcp engine..

http://server.voidrpg.com/network test2.rar

readyfor use. and its same speed as UDP !


Pinete(Posted 2006) [#28]
broken link!!
:_(


Steven Noyce(Posted 2006) [#29]
Just copy and paste the whole thing into your browser and it works fine!