Using UDP and TCP?

I thought of this crazy idea…
In my engine I want it possible to quickly send messages (UDP) but sometimes send a message while knowing that it will make it to the other end (TCP)…

Is it such a crazy idea to use both along with using a MultiCast socket for finding servers?

The only other way that I can think of is to use UDP and if the message is important, the end thing will send back acknowledgment… But the problem is how to detect when it the end thing doesn’t receive it? I thought of a timer, waiting for acknowledgment, but if the timer is too short than low internet could be classes as a failed message and if you make the timer too long then there would be lag…

What is the best idea to use?
And please don’t give me some sort of library… Say ‘reinventing the wheel’ as many times as you want but I’m still making this myself…

Checksums.

UDP & TCP serve different purposes; if you have needs that are fulfilled by using both, then it’s absolutely right to use both.

If it’s any reassurance, there are lots of AAA games that use.

First off, don’t use a timer to detect if packets have been received. If anything send back a confirmation packet. A timer usually runs on a separate thread so there’s all sorts of crazy logic going on there.

Second, using both can sometimes mess with each other. Do your research first on how to resolve this.

Third, I really advise you NOT to do this yourself. I know its tempting to want to code everything yourself, but networking is definitely something where its much easier just to use someone else’s library that is already optimized. Kryonet exists; its super fast, safe and easy to use and trust me, there is no point in reinventing the wheel here. It would be wise to listen to people that say that, by the way. We were all once there, trying to reinvent the wheel. Ask anyone how successful they were with that and most will respond with a “not very”. Learn the concepts and the way it works, but don’t re-program a library that has been optimized for years, like kryonet.

Using TCP and UDP together increases the packet loss of UDP.

What?

Thx

I am sending confirmation back… But I want to know how to detect when there isn’t a confirmation so the server can have another attempt at sending the important message.

AND

I think it will be ok if some of the UDP messages are lost… Also the TCP isnt used much and only used or important messages…

I don’t really care if it is going to take a while… I like to have something that will occupy my time…
I don’t really care if it is going to be hard… CHELLENGE ACCEPTED…
I don’t really care if there is going to be a lot of bugs… I’m a programmer, I’m used to it…
Maybe when I’m actually in the game biz, then I might use other people’s stuff but at the moment I would at least want to try to make my own version…

Checksums: http://en.wikipedia.org/wiki/Checksum

CopyableCougar4

Still lost…
so… Checksums makes a number from a peice of data? How does that help? Can you please explain?

Checksums can be used for detecting transmission errors.

Quote:

[quote]for the purpose of detecting errors which may have been introduced during its transmission or storage
[/quote]
CopyableCougar4

checksums arent really applicable here, they’re mostly used to compare sets of data across server/clients for consistency. that being said, you cant check that you lost a udp packet.

So… if I’m right…

If you told someone else ‘I like household cats’ and they heard ‘I like baseball bats’ you can tell them ‘my previous sentence has something to do with animals’ they can think ‘well… something like cats, dogs or birds has to do animals… but baseball bats dont…’ and they can ask for what you said again…

Is this how checksums work?

If you take the term ‘checksum’ literally, it’s a check that some sum of parts of your data equals the sum of parts of other data.

Let’s say you have the following data to transmit:
9,76,4,80,147
We can take the sum of all digits:
9,7,6,4,8,0,1,4,7 --> 46
Now we send 46 along with our data.

The receiver can do the same thing on his end. If the sum is not equal, data corruption has occured - either in the payload or in the checksum itself. Note that checksums are not meant to be failsafe. More than one flipped bit might produce the same checksum for a different payload.

What this has to do with ACKing UDP packets… I have no idea.

Ok… So I understand how checksums work… But how do make sure the packet was successfully sent and received at the other place to start of with? Or is it just better to just use UDP and TCP together?

I kinda misunderstood your problem. I thought you were asking how to check if data is intact after being sent. From my perspective, you should just use TCP for 100% delivery.

I tried that but there was lag problems… Also, when there is a lot of moving objects, a lot of data is being sent of TCP which seemed to be buffering up the stream…(I believe that is the right term…)

You set TCP_NODELAY?

Anyone here tried using SCTP? - http://www.oracle.com/technetwork/articles/javase/index-139946.html

So this TCP_NODELAY is faster but there could be problems? Is there also ok to just disable TCP_NODELAY just for a tiny bit to send an important message?

I don’t understand. I thought you needed TCP for important stuff like important data, which is almost never sent. If you are streaming something every update cycle, then you should be using UDP for that.

Yes… but what about messages like ‘something being created’ or ‘something being destroyed’?

I don’t think that’s how you use UDP. It should be more like ‘I have these objects which are doing this’. The message could be like

An entity which is running from tile [0, 0] to tile[0, 10]

EDIT----
I wonder how often do UDP packets get lost. If a player, for example, issues a move command, I doubt there are many times that the packet will not be received by the server through UDP.