UDP vs TCP
-
iceshaft07
- Posts: 33
- Joined: 28 Jan 2011, 20:10
UDP vs TCP
Hello;
With Unity, UDP can be initialized. I was wondering if there is a way to send some extension calls via TCP and some via UDP--
So, I would update positions via UDP, but send player kills via TCP. Is there any way to do this?
With Unity, UDP can be initialized. I was wondering if there is a way to send some extension calls via TCP and some via UDP--
So, I would update positions via UDP, but send player kills via TCP. Is there any way to do this?
-
ThomasLund
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Sure - the extension request constructor takes a boolean for if you want to send this particular request as udp or tcp
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund
Traffic flow.jpardoe wrote:Stupid question here: What are the benefits of using UDP over TCP?
Assuming you time code your packets, we're going to ignore out of order packets.
So it comes down to whether you want the stream to suddenly halt/wait if one of the packets takes a longer route. UDP just keeps going and going.
Yes, and that's why iceshaft wants to put transient data like position on UDP and guaranteed data on TCP.jpardoe wrote:So if we put that into context...
In a real-time game, say a player fires an arrow.
In TCP if the packet takes a long route, the game will pause (lag)?
In UDP the packet would be dropped and so other players would not see the arrow being fired.
Correct?
You could always rebuild the TCP protocol on UDP and just keep one socket, but that's another fun-filled post I'm too tired to get into.
Last edited by tchen on 24 Feb 2011, 06:13, edited 1 time in total.
-
ThomasLund
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
And there is an even longer discussion about UDP not always being the best choice either. There are some overheads too + it takes a larger toll on network equipment having to inspect each and every UDP packet. Etc.etc.
So dont use UDP as the wonder weapon to kill em all.
But in rough terms:
- if you have throwaway data that you send often, then UDP is nice. Transforms for example
- if you have one shot messages that _have_ to get through, TCP is your choice. Login, chat, payment - those kinds of things
For things in between - its up to you
/T
So dont use UDP as the wonder weapon to kill em all.
But in rough terms:
- if you have throwaway data that you send often, then UDP is nice. Transforms for example
- if you have one shot messages that _have_ to get through, TCP is your choice. Login, chat, payment - those kinds of things
For things in between - its up to you
/T
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund
UDP
For a good example of how some tcp high level features are used on top of UDP check out ENET,
its in c++ but you can download the code and look through it if your really interested. More low level than smartfoxserver though.
its in c++ but you can download the code and look through it if your really interested. More low level than smartfoxserver though.
-
ThomasLund
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
If you want reliable UDP, someone already invented that. Its called TCP
/me ducks the religious peons who throw things at me for the provoking statement
/me ducks the religious peons who throw things at me for the provoking statement
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund