Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
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  
  Java Chat Client/Server Architecture  (Read 3382 times)
0 Members and 1 Guest are viewing this topic.
Offline Jack9C

Junior Newbie

« Posted 2008-07-23 22:26:56 »

I have built a Java chat client and server using Xsocket (see: ) which is going to act as a game lobby for a virtual card-game.

The clients are single threaded applications that use my own ad-hoc custom-event driven GUI framework.
(see the framework basics: )

The server uses NIO channels. New connections spawn threads which called "connection handlers" which interpret/validate messages and fire off valid network messages as events (I send serialized objects between client/server). The server uses the same GUI framework for a console.

First, I'm interested in if people use this type of network flow or why they do not (other than speed of updates which is of large concern to other types of frame dependent games)?
Offline noblemaster

« JGO Spiffy Duke »

Medals: 24
Projects: 10

Age of Conquest makes your day!

« Reply #1 - Posted 2008-07-23 22:33:41 »

How is the communication implemented? Are you send data via HTTP, i.e. HTTP tunneling?

Offline Jack9C

Junior Newbie

« Reply #2 - Posted 2008-07-23 22:36:35 »

I am opening a Nonblocking socket to the server on a particular port. There is no specified protocol, just serialized objects as streams.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

« JGO Spiffy Duke »

Medals: 272
Projects: 25
Exp: 18 years

Coder, Trainee Pixel Artist, Game Reviewer

« Reply #3 - Posted 2008-07-24 07:28:15 »

Spawning a new thread per connection isn't a scalable approach. One of the reasons NIO provided accessors to fd_sets and selectors was to allow scalability. Thread creation is first time consuming and second often eats system resources very quickly. This provides some good information though isn't totally apt:

Using default serialization is a bit of an network overhead but for the purposes of a non-realtime game probably doesn't matter too much.


Offline Jack9C

Junior Newbie

« Reply #4 - Posted 2008-07-24 21:26:02 »

Ok. So I've removed thread spawning and use the selector approach.

What about the event-driven model for network messages? As I understand it, the event dispatching is a separate thread. So I think it's fine for me.

When I attempt to send multiple messages from the client (which go out to the server before coming back to the client as all messages should), I get bad behavior from the DefaultListModel or JList or JScrollPane. I get inconsistent scrolling using MyJList.ensureIndexIsVisible(lastIndex); sometimes the last message is visible sometimes it's not and sometimes the messages are rearranged when displayed (I started tagging them all with an integer to observe the behavior). Is there a better Model to use or a reason this might be happening?
Offline cylab

JGO Wizard

Medals: 89

« Reply #5 - Posted 2008-07-24 22:35:07 »

Are you updating the ListModel/JList/JScrollPane from the AWT event thread or from another thread? Swing is not thread safe, so if you modify Swing components from a different thread than the AWT event thread, you can get all kinds of strange behaviours...

Mathias - I Know What [you] Did Last Summer!
Offline Jack9C

Junior Newbie

« Reply #6 - Posted 2008-07-25 03:42:14 »

Are you updating the ListModel/JList/JScrollPane from the AWT event thread or from another thread?

I'm not sure. It's funny that I can grasp NIO but not this stupid GUI problem. I have a JFrame with a Text Input that has a keylistener added to it

                new KeyListener()
                   public void keyPressed( KeyEvent e )
                      if (e.getKeyCode() == KeyEvent.VK_ENTER)
                   public void keyTyped( KeyEvent e ){}
                   public void keyReleased( KeyEvent e ){}

Send message is defined:

   public void sendMessage(String message)
      fireCranegormEvent(new ClientChatEvent(Constants.CLIENT_DISPLAY_MATCHMAKER, MVC_Provider.getUserModel().getId(), message));

The constructor of the JFrame has


The event controller is what hears and handles ALL events. When a network message is received from the server, the event controller modifies the DefaultListModel, which is assigned to the JList, which is contained in a JScrollPane. Is this somehow broken? It works really well for everything so far, excepting this JScrollPane problem.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (11 views)
2015-07-29 04:35:27

Riven (33 views)
2015-07-27 16:38:00

Riven (17 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (29 views)
2015-07-25 00:14:37

BurntPizza (40 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (27 views)
2015-07-22 22:16:53

NoxInc (18 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!