udp or tcp

Blitz3D Forums/Blitz3D Beginners Area/udp or tcp

grindalf(Posted 2009) [#1]
which one is bettter UDP or TCP and also when i was testing out TCP it was asking for a port number, how do i find out my port numbers
it was set to 8080 but i couldent get my computers to find each other like that


Mahan(Posted 2009) [#2]
TCP - Controlled stream-like transfer, guarantee'd delivery.
UDP - No delivery control at all and packet based.

Some interesting posts to read:

http://blitzmax.com/Community/posts.php?topic=81852#922028
http://blitzmax.com/Community/posts.php?topic=81738#920881
http://blitzmax.com/Community/posts.php?topic=76325#853773
http://blitzmax.com/Community/posts.php?topic=74970#840454

(hint: Searched Blitz3D-forum for the word "udp")


grindalf(Posted 2009) [#3]
thanks for the links, I guess from reading those topics that tcp is not worth considering.
one more thing is will this work with lan cable, because i havent manged to get it to sofar(it says cannot connect to server o the second computer)
I figured that was becausee of the port number(8080) but i dont really know why I thought that.
is the port port number 8080 ok? for the lan, or for wifi internet. I really dont get the port numbers =(


grindalf(Posted 2009) [#4]
ok Ive been looking into the port numbers and i get it a bit more now
for instance if im useing port 80 and i then open internet explorer one of the two will crash, correct?
anything above 1027 is free to use so a number like 8080 should be fine. the problem i was having before must have been a codeing thing on my part.
thanks for the pointers =)
let me know if im wrong on anything


xlsior(Posted 2009) [#5]
You can bind a program to port 80 and use internet explorer just fine, since IE isn't actually *listening* on port 80 for incoming requests. However, you would run into problems if you try to run a webserver liker IIS or Apache which binds to port 80. (As do some other applications -- for example, I found out the hard way that Skype also binds port 80 by default. apache failed to install for me initially because of that)

If you're curious what ports are in use by your PC, you may want to try running sysinternals TCPView.


Mahan(Posted 2009) [#6]

thanks for the links, I guess from reading those topics that tcp is not worth considering.



Nope, I'm very sorry if i gave you that impression. It's all up to what you want to do. Your initial question was:


which one is bettter UDP or TCP [...]



And the answer is that they are two different things. To bring an infamous car analogy I'd illustrate it this way:

Which one is better [Korean car with 1.1 litre engine, 60hp] or [Trailer Truck 18-wheeler, 900hp]?

They both have their similarities (like being a means of transport) both they also have huge differences (like 5L/100km vs 30L/100km and 250kg cargo vs. 50000 kg cargo capacity)

Both tcp and udp are viable for gaming, and on the forums/code archives you'll find working examples of both that you can try for yourself and see what you like best. (If you're interested in TCP find some code written by Wings. I remember testing some example by him that I liked, because it worked quite well)

udp is generally faster and better response times but often requires more control code written by the developer.

Hope this helps a bit.


Blitzplotter(Posted 2009) [#7]
I did a little work using Blitz3D a while back with a modified version of Wings code, the downloadable VB.net front end just modifies a text/ini file that the server & client(s) code refers to - its here:

http://www.blitzbasic.com/Community/posts.php?topic=76772#862906

you will notice the client just uses the loopback address of 127.0.0.1 on port 7056 so that you can run the clients and server on the same computer for development.

hope it is of some use.


grindalf(Posted 2009) [#8]
Thanks for all the help.
Ive been doing some work with UDP and have a server which players can log onto and then control a cube. they can see the other peoples cubes moveing around. its working really well so Im gunna try and make a real game now(no cubes)


Blitzplotter(Posted 2009) [#9]
udp is less time intensive, good luck with your approach grindalf.


Gabriel(Posted 2009) [#10]
Hopefully you've read enough of what Mahan posted to know that UDP messages are not guaranteed and not ordered. That is to say that if I send out messages 1,2,3,4 and 5, the client might receive messages 3,1 and 4, in that order. 2 and 5 were lost, and message 3 came before message 1.


Blitzplotter(Posted 2009) [#11]
@Gabriel, that is a good point, hopefully grindalf has some header information within his UDP messages which will account for this - not too hard to implement data that will combat your suggested potential issues.


grindalf(Posted 2009) [#12]
I already have it dealing with messages not beeing recieved but i didnt know they can be sent in the wrong order, I dont think it should be a problem but at least i can code things in advance for that.

does anybody know what the succes rate of sending a message in UDP is and whats the chances of the order being wrong(my bigest concern)


grindalf(Posted 2009) [#13]
one more thing, can i use tcp and udp kind of at the same time, for instance use udp for player positions which wouldent crash if its not recieved every messsage but for level data use tcp which would need to be sent in the right order and would need to be sent or parts wouldent load and the level would either load wrong or crash. Im sure i could quite easily put sequrity into this so it would be fine, but if i can have a udp and tcp stream with no problems then that would be much better


PowerPC603(Posted 2009) [#14]
I guess you could do that.
I've never done anything like sending TCP or UDP messages, but from the docs, you need to specify a port to which you send and receive data from.

I guess you can create a TCPStream on port 9000 for example,
and the UDP on 9100.

Just use different ports for both protocols.