Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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 2841 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: http://xsocket.sourceforge.net/ ) 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: http://forums.dzone.com/java/372-java-gui-framework-cranegorm.html )

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 Ninja


Medals: 20
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 Kernel


Medals: 153
Projects: 23
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: http://www.ibm.com/developerworks/library/j-jtp0730.html

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.

Kev

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 Ninja


Medals: 43



« 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 »

Quote
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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
inputTextField.addKeyListener(
                new KeyListener()
                {
                   public void keyPressed( KeyEvent e )
                   {
                      if (e.getKeyCode() == KeyEvent.VK_ENTER)
                      {
                         sendMessage(inputTextField.getText().trim());
                         inputTextField.setText("");
                      }                      
                   }
                   public void keyTyped( KeyEvent e ){}
                   public void keyReleased( KeyEvent e ){}
                }
             );


Send message is defined:

1  
2  
3  
4  
5  
   public void sendMessage(String message)
   {
      fireCranegormEvent(new ClientChatEvent(Constants.CLIENT_DISPLAY_MATCHMAKER, MVC_Provider.getUserModel().getId(), message));
      inputTextField.setText("");
   }


The constructor of the JFrame has

1  
      addCranegormEventListener(MVC_Provider.getGC_EventController());      


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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (26 views)
2014-08-19 14:29:53

Tekkerue (24 views)
2014-08-16 11:45:27

Tekkerue (23 views)
2014-08-16 11:22:17

Tekkerue (14 views)
2014-08-16 11:20:21

Tekkerue (22 views)
2014-08-16 11:12:11

Rayexar (60 views)
2014-08-11 07:49:23

BurntPizza (38 views)
2014-08-10 02:09:32

BurntPizza (30 views)
2014-08-08 07:01:56

Norakomi (37 views)
2014-08-07 00:49:38

BurntPizza (67 views)
2014-08-03 07:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!