Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Using UDP and TCP?  (Read 8388 times)
0 Members and 1 Guest are viewing this topic.
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Posted 2014-10-12 12:09:36 »

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...

Is it sad that I still get a fright when the computer beeps at me...
Offline trollwarrior1
« Reply #1 - Posted 2014-10-12 12:26:47 »

Checksums.
Offline Abuse

JGO Ninja


Medals: 70


falling into the abyss of reality


« Reply #2 - Posted 2014-10-12 12:45:45 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Opiop
« Reply #3 - Posted 2014-10-12 13:34:12 »

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.
Offline HeroesGraveDev

JGO Kernel


Medals: 382
Projects: 11
Exp: 4 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #4 - Posted 2014-10-12 19:52:23 »

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

Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #5 - Posted 2014-10-12 22:17:21 »

Checksums.
What?

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.
Thx

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.
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.

Second, using both can sometimes mess with each other. Do your research first on how to resolve this.
AND
Using TCP and UDP together increases the packet loss of UDP.
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...

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.
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...

Is it sad that I still get a fright when the computer beeps at me...
Offline CopyableCougar4
« Reply #6 - Posted 2014-10-12 22:38:10 »

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

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #7 - Posted 2014-10-13 00:19:02 »

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

Is it sad that I still get a fright when the computer beeps at me...
Offline CopyableCougar4
« Reply #8 - Posted 2014-10-13 00:28:26 »

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

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Agro
« Reply #9 - Posted 2014-10-13 00:37:15 »

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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #10 - Posted 2014-10-13 06:17:00 »

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?

Is it sad that I still get a fright when the computer beeps at me...
Offline Riven
Administrator

« JGO Overlord »


Medals: 1356
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2014-10-13 07:16:09 »

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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #12 - Posted 2014-10-13 09:46:51 »

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?

Is it sad that I still get a fright when the computer beeps at me...
Offline trollwarrior1
« Reply #13 - Posted 2014-10-13 10:29:45 »

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.
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #14 - Posted 2014-10-13 10:54:41 »

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...)

Is it sad that I still get a fright when the computer beeps at me...
Offline nsigma
« Reply #15 - Posted 2014-10-13 10:58:33 »

I tried that but there was lag problems...

You set TCP_NODELAY?

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

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #16 - Posted 2014-10-13 11:35:34 »

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?

Is it sad that I still get a fright when the computer beeps at me...
Offline trollwarrior1
« Reply #17 - Posted 2014-10-13 12:15:12 »

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...)

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.
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #18 - Posted 2014-10-14 02:57:44 »

Yes... but what about messages like 'something being created' or 'something being destroyed'?

Is it sad that I still get a fright when the computer beeps at me...
Offline trollwarrior1
« Reply #19 - Posted 2014-10-14 05:02:44 »

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.
Offline RobinB

JGO Ninja


Medals: 45
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #20 - Posted 2014-10-14 07:54:29 »

UDP still does checksums.. you get a packet or not, nothing between (packet loss is between 5% and 1% in normal situations and without TCP).
Its more about sending confirmations for important messages yourself.
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1314 views)
2018-06-10 19:43:48

EgonOlsen (1179 views)
2018-06-10 19:43:44

EgonOlsen (916 views)
2018-06-10 19:43:20

DesertCoockie (1317 views)
2018-05-13 18:23:11

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1338 views)
2018-04-24 18:14:32

ivj94 (2080 views)
2018-03-24 14:47:39

ivj94 (1231 views)
2018-03-24 14:46:31

ivj94 (2230 views)
2018-03-24 14:43:53

Solater (798 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!