For turn based you can easily use event based triggering, listener etc.

To trigger events on the event dispatcher thread use Eventqueue.invokeAndWait() This should allow you to avoid most of the complexityeffort involved with multi threading. You just need to focus a bit on managing the 'remote game'(network connection). Creating your own eventqueue isn't that difficult either if you do all the drawing you self - but since it's turn based your probably not using active rendering.

Oh and looking at executors is always a good idea, though with the event based approach you won't need it on the client. server-side it might work out depending on your approach.

i am using active rendering however im still relatively new to java so i dont quite understand the eventqueue you mentioned. could you explain it a little more fully or is there a good site with some reading on this subject?

Eventqueue is a way to have inter thread communication where no thread ends up waiting for one an other at the sacrifice of the 'sending' thread not knowing exactly when the other thread notices it.

A real life example is the mail-man and you, you might never see the mail man but you do receive mail. This is because you have a mailbox which you occasionally check. Since you don't have face to face contact you never have to wait for the other to be ready to receive. (in other words synchronise yourself with the mail-man) Other analogy would probably be 'just leave it on my desk if I'm not there'.

Depending on where you want the code(/logic) to reside you can either submit runnable's or events to a ConcurrentQueue. Or hybrid approach off-course (event containing a runnable).

i downloaded the jar you gave but how do i run the program and read the code? Im sorry i have never used a jar before....

also i think there has been some miscommunication because as i was thinking about it the postman and me example isnt really what im talking about. Everything im talking about is client side. Basically i want animations to continue while the client is waiting for info to come in. Basically i want my animations thread to check, somewhere in the loop, to see if there is a new message and if not continue doing whatever it was doing.

so to give an example say im using an instant messanger. Im doing laundry but as soon as my friend sends me a message i leave and go see a movie or whatever. i am the thread and while doing laundry i periodically check to see if there is a new message, if not i continue what i was doing, if so i alter what i was doing. The problem i run into in my program is that i cannot wait for a message while doing laundry. I have to wait for a message to come in and then i can continue the laundry.

hmmm after more consideration maybe you do know what im talking about..... so is the eventQueue like a mailbox? when one thread reads in data it writes something to the queue and the animation loop checks the queue for new info periodically? and then if new data is recieved it acts accordingly and removes the data?

if you could somehow make eventQueue analogous to real life it might help....

hmmm after more consideration maybe you do know what im talking about..... so is the eventQueue like a mailbox? when one thread reads in data it writes something to the queue and the animation loop checks the queue for new info periodically? and then if new data is recieved it acts accordingly and removes the data?

Bingo.

I need to stick the source in a jar here because zip can't be attached to messages. Since a jar is basicly a zip, you can just unzip the jar. (renaming it works)

Quote

if you could somehow make eventQueue analogous to real life it might help....

Network Thread is your friend.You are the gameloop.EventQueue are your mobile phones.

i know all that but the link to the download doesnt appear to me anymore. and as for the applet thing my game is an applet but i think i figured it all out so i don't need the jar anymore.

also one quick thing.... if you know a lot about networked gaming could you briefly summarize how lobbies are made? just a simple one where users can chat and possibly challange each other to a game....

If you conceptualise your problem and group actions that are similar The design should be straight forward.

Technically for chat you could do the same thing but on the server aggregate any messages on a queue then at the head of the queue poll and 'broadcast' it back to every client. As for lobby like functionality depends on what you want battle.net like: separate chat separate list. Integrated send invite messages to ppl in the chat. I suppose I could draw that up for you but that would only make you slowly more and more depended on others to come up with the design. Diminishing your usefulness for a company and making future job interviews more difficult for yourself. As questions related to these kind of problems usually is the meat on the bone(or w/e the right metaphor is.)

i was not asking you to write the code for me (but its very kind of you to offer) nor am i ever going to work in the field of game programming. im a mechanical engineer major at the university of texas and recently took a class on java and thought it might be fun to develop a game.

i was merely asking conceptually how lobbies are handled. i was thinking the queue thing would be good for messages like you said however how do you handle the list of people in the lobby? Currently with the game i have when a user connects to the server it creates an object out of that player and then it matches players up together and creates a game object and passes the two player objects as parameters. so i was thinking since each user is already an object it wouldn't be too hard to use maybe a resizable array and as each new user connects to the server add them to the array?

probably not the best way? am i at least heading in the right direction making each new user a player object?

Arrays are like udp you don't need them unless you know for an unmistakable fact that you do.

Always use an List or a Set or if you write some method that does some function that can be applied to both use a collection - since most of those methods are already made for you: use an List or Set.

Yes from a servers point of view a socket can be seen as abstraction of a connection / remote node / client / player. Since you likely want to store information more information(like name for example) wrap the socket in a object - use the highest possible abstraction and code against it. Put these in a Set and your there. No one ever said anything needs to be hard or complex to work, so yes that's the right direction.

whats the best way to link a name to a particular socket? have the server accept the username from the client and then create another object out of the shotplayer and the username? <<< doesnt seem like the best way but was what i was thinking.

Difference between a Set and a List is the same as the mathematical interpretation.

They are both collections, Set is by default unordered and contains no duplicates (SortedSet is an ordered one without duplicates, equality is defined by the equals() method defined in object (override where necessary together with hashcode() -> why they are linked check google) with a List the determining factor is the order and permits duplicates.

Whether null element is allowed is dependent on the implementation.

Implementations to use as defaults are as follows:List - ArrayListSet - HashSetSortedSet - TreeSetDon't change them unless profiling dictates that they should be changed.

As for your code, in this particular case I would go for composition. (just google Composition versus Inheritance)

i think im having a bit of a problem with the event dispatcher. im trying to create my lobby with chat and so far i have a text field for the user to type messages in and a text area that displays all messages and a button to send messages with. However, after the client has recieved the message from the server i cannot get it to display with the textarea.append(String) method. i have tried researching it on google but it doesn't make much sense to me.

any advice? i know for a fact the problem is not the server because if append is called from a button click it will work but not when called in a run method.

Well the general rule of tumb has been that if you use active rendering you should stay away swing.

Dependence on how your gui is set-up. If the components are going to be in your in your active rendering bit I would chose neither as far as widgets are concerned. Make your own as it's probably less work and ppl don't expect a game to integrate with an OS anyway. I mean games are suppose to be fun - OS's are dull. the only thing you should perhaps pay attention to is that those self written widgets should grow as the resolution increases. But since those aren't 'part' of your game you can just draw them bigger.

you pretty much addressed a question i would have asked down the line becuase you are right the supplied textField and buttons are boring. How do you go about creating your own?

as for my lobby system i have a chat system up and running however now i want each client to be able to see a list of the users connected (and possibly at some point have private chat and challange a specific user to a game). im using arraylist on the server side for all users that are connected but how in the world are you supposed to transfer and entire arraylist to the client and also update it as people come and go?

you pretty much addressed a question i would have asked down the line because you are right the supplied textField and buttons are boring. How do you go about creating your own?

Just draw them as any thing else in your game but don't make them apart of your logic and draw them a-top of everything else, on mouseclicks check if there is a 'component' on that coordinate and dispatch a mouse event to that component. That should make implementing buttons straightforward. as for text fields, have a object in which you track focus, have it contain the object that has focus and what (keyboard)events it's interested in. Append keys to the string resp remove on backspace. All the tedious stuff like validation etc are probably overkill for your game just filter A-Z + -_ or something for names. As for tracking which 'component' should have focus just add additional logic between the 'check-if-theres-a-component-at-that-coordinate' and 'dispatch-event-to-component'

as for my lobby system i have a chat system up and running however now i want each client to be able to see a list of the users connected (and possibly at some point have private chat and challange a specific user to a game). im using arraylist on the server side for all users that are connected but how in the world are you supposed to transfer and entire arraylist to the client and also update it as people come and go?

First you must figure what behaviour you demand from client. Is it really that much of a problem if the user list goes out of sync if so how short should syncing be. Since your using tcp with it's guaranteed delivery as long as your connected, you can also go with sending the chat list on enter and publish modifications(join/leave) to your clients. You can also go hybrid and send modifications and do a complete sync occationally.(Considering your using tcp - going out of sync, given that you can guaranty that publishing is always done, is impossible.)

As for the next step, make sure your familiar with (de)multiplexing - (data and it's context) vs (data + metadata outside of context).(there are perhaps easier explanations of this concept google) Context takes up no space so it's 'free' - how things are put into context is defined by a protocol.

Some examples:(if ordered:)Does cas like pie?yes. Is Java hard to learn?no

(from the context you can derive that the answer follows directly after the question. - human protocol - humans aren't physic so it could hardly be any other way)

What where the answers to the teacher's questions?yes, no

(almost no one is going to answer that way as ppl generally mess up the order - if they remember the questions at all. Also if the questions where asked on different occasions, you might not even be sure you got the same questions)

What where the answers to the teacher's questions?Java wasn't hard to learn.Cas likes pie.

As you can probably spot if you can make use of the context you need less text to answer.

You can derive the same information from both data one just makes use of the context and is smaller. - off-course this only matters if you care about bandwidth esp as constructing information from context might eat away at other resources.

An example would be vectorised graphics, they are smaller but require more processing power to put on the screen.

As you might have picked up from earlier examples transfering a List Strings can be represent a a String itself easily enough. Strings can easily be converted into bytes which can be send. Now you don't have a list of Strings you probably have a list of player objects. Select first what you actually want to share(which data on the server you might keep the ip adress around on the player object - doesn't mean you have to send it to your clients) make up a format convert it to string or directly to bytes.

A pointer here:

class Player { String name; ...}

Player one = new Player("Michael");one.asMessage() -> "Michael"Player two = new Player("Michael");

one.equals(two) -> false - please note that you did have loss of information here: whilst multiplexing and demultiplexing you lost object identity, you probably don't care about this but in other similar causes you might care.Simple solution is to define your object identity differently (override equals + hashcode to use name).

Regarding identifying - say you uniquely define players by firstname lastname it's probably not a good idea to repeat that every message as that takes up relatively a lot of space esp if your identifier uses a lot of fields, now dba's figured out long ago that using a unique number is usually more efficient.

A final timbit of information: a integer 1000 takes a lot less bytes as four chars: '1' '0' '0' '0'. - again this might or might not matter also if your lazy you can always just compress your stream characters though hand tuned 'compression' is probably more efficient.

I would recommend sticking as doing clever things with bytes is probably premature optimalisation.

hope these pointers help, feel free to specify where I messed up -> made it way too obscure.

//edit hmm should probably add a timbit about separators and escape characters data

first of all wow thanks for the help i cant imagine how long it took you to write all that.

creating widgets seems simple enough however textField seems like it could be a bit complicated. For instance scrolling? in the chat i would like each new message to be on a new line and obviously when the text reaches the bottom of the screen or widget it should be scrollable. how do you implement that?

as for transfering the userlist i already have each player objected created with a userName to identify it and yes thats all i need to transfer not the actual object. I believe i will go with when a user connects the server sends the current user list and later on sends an update with a leave/join.

getting into protocol is kinda where things get confusing because the server and client have to send so many different types of messages. im having trouble making the client understand what to do with the data it recieves. it seems like an easy way to do this (tell me if this is even possible) would be to say:

update: userNameremove: userNamemessage: "message"etc.

preface the type of message like above or even shorten it to just one letter and a colon to represent the type of message. however after that is there a way to remove a portion of a string? for instance with message: "message" i would have to remove "message:" and display the rest to the user.

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