Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Updated network API  (Read 4131 times)
0 Members and 1 Guest are viewing this topic.
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Posted 2004-04-04 15:53:00 »

The New Dawn network API has been updated to use NIO. It's lower level than herks headquarters engine, it just sucks up and spits out 'Message' objects across a TCP link. I'm still evaluating the benifits of UDP (yes i have read 'The' thread Smiley). When I get far enough along with darkvoid to make my own observations I will see if I can be bothered Smiley.

Source, javadoc and an example app are included.

Comments and critisims are welcomed

Cheers

Endolf

Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #1 - Posted 2004-04-05 04:43:09 »

Quote
It's lower level than herks headquarters engine, it just sucks up and spits out 'Message' objects across a TCP link.


Smiley  ... well, HeadQuarters package 'objectbus' does that as well and is also meant to be used on that level. So only some parts of HQ are high level (those that maintain a distributed state or implement a predefined service like chat or clock sync).

JPilots 'I shot!' messages are of that kind....

(is this already a shameless plug now?)

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #2 - Posted 2004-04-05 05:06:09 »

Quote
(is this already a shameless plug now?)


Yes Smiley, but we'll let you off in return for the same later Smiley

Endolf

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

JGO Coder


Projects: 2


Fire at will


« Reply #3 - Posted 2004-04-05 11:44:48 »

what's the url?  I looked at http://www.newdawnsoftware.com/ but couldn't see it.

Cheers,

Wil.

Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #4 - Posted 2004-04-05 11:46:43 »

Hi
 From the main site follow the links to resources, and Early Access Libraries.

HTH

Endolf

Offline MickeyB

Senior Devvie




my game will work, my game will work!


« Reply #5 - Posted 2005-06-07 17:39:19 »

How is dark void coming along?  Still using the API from the new dawn site for networking?

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline CommanderKeith
« Reply #6 - Posted 2006-04-01 03:07:49 »

Hi Endolf and Kev,

I like your NIO API, its quite elegant and simple.  I examined your code and ran my own tests and I noticed that the recieveMessage method would return null twice before it returned a message, even when I knew the message was waiting there.  So I changed the method to this, and it works as it should:

   public Message readMessage() throws IOException {
      int addBytes;

      if (invalid) {
         return null;
      }

      if (state == WAIT_FOR_CODE) {
         addBytes = channel.read(shortBuffer);

         if (addBytes < 0) {
            invalid = true;
            throw new IOException("Connection closed");
         }
         read += addBytes;

         if (read == 2) {
            messageCode = shortBuffer.getShort(0);
            shortBuffer.rewind();
            state = WAIT_FOR_LENGTH;
            read = 0;
         }
         //return null;
      } //else if (state == WAIT_FOR_LENGTH) {
      if (state == WAIT_FOR_LENGTH) {
         addBytes = channel.read(shortBuffer);

         if (addBytes < 0) {
            invalid = true;
            throw new IOException("Connection closed");
         }
         read += addBytes;

         if (read == 2) {
            messageLength = shortBuffer.getShort(0);
            bodyBuffer.limit(messageLength);
            shortBuffer.rewind();
            state = READING_BODY;
            read = 0;
         }

         //return null;
      } //else if (state == READING_BODY) {
      if (state == READING_BODY) {
         addBytes = channel.read(bodyBuffer);

         if (addBytes < 0) {
            invalid = true;
            throw new IOException("Connection closed");
         }
         read += addBytes;

         if (read == messageLength) {
            Message message = factory.getMessage(messageCode);
            if (message != null) {
               ByteArrayMessageEncoder.decode(message,bodyBuffer.array());
            }

            bodyBuffer.rewind();
            state = WAIT_FOR_CODE;
            read = 0;

            return message;
         }

         //return null;
      }
      return null;
   }

Good idea?

Also, how hard would it be to adapt your library to UDP NIO?

Thanks,
Keith

Offline sunsett

Senior Devvie




ribbit!


« Reply #7 - Posted 2006-04-03 12:40:06 »

Interesting API.  I would submit that if you're going to be having to encode and decode your messages yourself anyway you might as well just utilize Java's built-in features directly.  Of course there are some inherent structural benefits to being able to abstract explicit messages the way the API does.

My API is also based around Message objects, but removes the need for encoding and decoding utilizing dynamic introspection and creation.  It's definitely higher level than this though.

-Matt Hicks
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #8 - Posted 2006-04-03 14:26:36 »

Guys,

The last post from Endolf on this thread was 2004 - ND Net hasn't been updated for the longest time - we've both moved away from it. I wouldn't suggest getting dependent on it.

Kev

Offline CommanderKeith
« Reply #9 - Posted 2006-04-05 03:28:56 »

Guys,

The last post from Endolf on this thread was 2004 - ND Net hasn't been updated for the longest time - we've both moved away from it. I wouldn't suggest getting dependent on it.

Kev

Sure.  But, I hope you won't mind if I use and modify your code....?

My API is also based around Message objects, but removes the need for encoding and decoding utilizing dynamic introspection and creation. It's definitely higher level than this though.

-Matt Hicks

The API is extremely low-level, and that's what's appealing.  It doesn't really try do anything more than send a byte array and recieve the byte array as a whole on the other side.  (I've slimmed the NewDawn code even further into 2 classes that just deal with byte arrays)

To do anything more than that then JGN or another network library would be great, but for 'roll-your-own' solutions (like my SS streams I suppose) then byte array send/recieve is all you want.

Keith

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

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #10 - Posted 2006-04-05 03:59:19 »

Incidently, this low level wrapping of byte arrays into arbitary messages pattern fits really nicely into the Project Darkstar world.

Kev

Offline otelo

Junior Devvie





« Reply #11 - Posted 2006-04-20 08:45:31 »

hi,

I consider myself a newb in the networking department, so please don't feel insulted should I be pointing out problems that are no problems at all. Wink

I was looking at the newdawn code and I have some questions concerning the ByteArrayMessageEncoder's encode method. I'll place my questions directly into the code block if you don't mind:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
 public static byte[] encode(Message message) throws IOException 
  {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
   
    DataOutputStream out = new DataOutputStream(bout);
    out.writeShort(message.getMessageCode());
    out.writeShort(0); // length
    message.encode(out);
   
    // considering you use a message structure of
    //
    //  CODE[2B] - LENGTH[2B] - BODY[variable_length] ,
    //
    // should the next two lines not be commented out?
   
    out.writeShort(message.getMessageCode());
    out.writeShort(bout.size()-4); // length
   
    // while using the following bitwise manipulations
    // to correct the message's length in your byte[] ,
    // why not use integer for length with the rest of
    // the code untouched? you would achieve the
    // equivalent of using an unsigned short increasing
    // the max length of your message from 32K to 64K,
    // which as Riven pointed out in another thread is
    // considered a drawback. this would also need to be
    // addressed in the Connection's readMessage /
    // writeMessage methods of course but why not?
    // nnot very elegant I guess.
    //
    // also, why not include a
    //
    // public short getMessageLength();
    //
    // in your Message interface and let people handle this
    // themselves?
   
    byte[] data = bout.toByteArray();
    short length = (short) (bout.size()-4);
    data[3] = (byte) (length & 0x00FF);
    data[2] = (byte) ((length & 0xFF00) >> 8);
   
    return data;
  }
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #12 - Posted 2006-04-20 11:25:44 »

Hi

It's all code I'm no longer using, feel free to make any modifications you want Smiley

Endolf

Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #13 - Posted 2006-04-20 14:32:41 »

Ditto, I've tried to point this out above!

Quote
ND Net hasn't been updated for the longest time - we've both moved away from it. I wouldn't suggest getting dependent on it.

Kev

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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (22 views)
2014-12-14 19:50:38

BurntPizza (43 views)
2014-12-09 22:41:13

BurntPizza (77 views)
2014-12-08 04:46:31

JscottyBieshaar (38 views)
2014-12-05 12:39:02

SHC (52 views)
2014-12-03 16:27:13

CopyableCougar4 (50 views)
2014-11-29 21:32:03

toopeicgaming1999 (116 views)
2014-11-26 15:22:04

toopeicgaming1999 (106 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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