home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-27 | 2.9 KB | 117 lines |
- // Simple Multiuser Server
- // (c) Copyright Justin Couch justin@vlc.com.au
- // The Virtual Light Company 1996
- //
- // From Chapter 20: Late Night VRML 2.0 and java
- //
- // This is the Chat message handler class. The real work of parsing an
- // individual message is done here and sending out messages to the other
- // users based on whatever filtering parameters are needed.
-
- package update;
-
- import java.net.*;
- import java.io.*;
- import filter.UserServer;
-
- class UpdateMessage extends Thread
- {
- private static int msg_number = 0;
-
- private int sequence_num;
- private int timestamp;
- private int entity_id;
- private float[] position = new float[3];
- private float[] rotation = new float[4];
- private int region_id;
- private float acuity;
- private int flags;
-
- private UserServer server;
- private DatagramPacket _packet;
-
- // all that gets done here is to copy over the packet into the internal
- // reference. We leave all the real work to the run method because that
- // allows java's thread handling system to share the workload much better.
- // If we didn't then the whole chat Server thread would block until we have
- // dealt with the response here.
- public UpdateMessage(DatagramPacket packet, ThreadGroup tg, UserServer userver)
- {
- super(tg, "Update Message " + msg_number++);
-
- setPriority(5);
-
- _packet = packet;
- server = userver;
- }
-
- // analyse the packet and send out the text to the other users.
- public void run()
- {
- int i;
- ByteArrayInputStream buffer =
- new ByteArrayInputStream(_packet.getData());
- DataInputStream data = new DataInputStream(buffer);
-
- try
- {
- // some quick checks on the first couple of bytes. If they are not
- // correct then just dump the packet by exiting.
- if(data.readUnsignedByte() != 0x80) // hex value
- {
- System.out.println("Update packet error: First byte not 0x80");
- return;
- }
-
- if(data.readUnsignedByte() != 79) // decimal value
- {
- System.out.println("Update packet error: Second byte not 79");
- return;
- }
-
- // sequence number
- sequence_num = data.readUnsignedShort();
-
- // timestamp
- timestamp = data.readInt();
-
- // Synchronisation source - Entity ID
- entity_id = data.readInt();
-
- // position
- position[0] = data.readFloat();
- position[1] = data.readFloat();
- position[2] = data.readFloat();
-
- // orientation
- rotation[0] = data.readFloat();
- rotation[1] = data.readFloat();
- rotation[2] = data.readFloat();
- rotation[3] = data.readFloat();
-
- // Region
- region_id = data.readInt();
-
- // acuity
- acuity = data.readFloat();
-
- // flags
- flags = data.readInt();
-
- server.send_update(_packet.getAddress().getHostName(),
- timestamp,
- sequence_num,
- entity_id,
- position,
- rotation,
- region_id,
- acuity);
- }
- catch(IOException e)
- {
- System.err.println("Update server error" + e.getMessage());
- }
- }
- }
-
-