About UDP

Hai!

I have tried for quite some time now, and I simply cant find a single quality tutorial/informative thread-something, talking about how UDP works within java.
Something that tells about why the amount of bytes are sent, and when they should be. Rechieving and sending.

If any of you have stumbled upon a such text, please link me!

Thanks

http://www.google.com/search?q=java+tutorial+udp
=> http://java.sun.com/docs/books/tutorial/networking/datagrams/index.html

It doesn’t get much clearer than that :slight_smile:

Now theres some questions that still stand a bit unclear.
How do I package something in a package client -> server, and how do I request a method to be ran client -> server or server/client?

The article just said how to send a string with a package, but how do I request methods to be ran? :slight_smile:

Try the library Kryonet

When the data is received on client or server, you should parse what is coming in the string. Imagine, you send from client to server following string: “upd_pos:1:10:15”. On server you got some kind of selector(at list I use to call the method which detects what request was received from client), which takes the first part of the string and analyze it. Selector detects that the first string is “upd_pos”, so it knows what is the method needed to handle the data, for example method updatePosition. You pass the string, or the unparsed part of the string to the method and the method updatePosition continues parsing.
There should be defined protocol, either made by yourself or already existing one, protocol is need for server to know what each string means. Though the string I gave you is just an example, in case of communication probably I would use JSON or in worth case XML(in my own practice using XML for RT games generates much more traffic then JSON).

So how excactly do I check the code for the protocol to know what to do? .startsWith("") ?

I’m not sure about if the JSON I’m positing is esthetically right, since the applications I made previously all used XML and after figuring out the problems using of XML I only planning to investigate how to pass that to JSON and how correct JSON is being created, but the string could look like:


{
    "request": "upd_pos",
    "character_id": 1,
    "line": 10,
    "column": 10 
}

Using GSON(library of Google that allows JSON) parsing you get every element of the JSON and you can parse the type of request which arrived depending on the “request” element.

yeah, but how is that string read, by the rechiever? How do you seperate the things?

Check this out :wink:

I am not using Gson, or any other extensive library. How do you do it in java manually?

That has nothing to do with UDP (or networking for that matter).

Please take the time to learn Java. That will get you somewhere, in the end. Even if we’d answer your questions directly, it’d be meaningless to you. It’s like asking for the rules in poetry in a foreign language - learn to speak it fluently first, then start with poetry. So much for the worst analogy ever.

Analogy?

Oh shut it :stuck_out_tongue: