vujxdp项目源代码(UDP via Jxta (not Jxta over UDP))

vUjxDP: UDP via Jxta (not Jxta over UDP)

Introduction

It all started because one day I wanted to send video and voice over Jxta for a chat application. My model using the Java Media Framework (JMF) was easy to develop.

JMF uses the Real Time Transport Protocol (rtp) over UDP. My application uses 2 video channels, 2 voice channels, 2 text/control channels. Since rtp is associated with a control protocol named rcp and Jxta needs two pipe for each TCP/UDP channel, this makes a total of 20 jxta pipes to deal with in a this 2 way-chat application.

Needless to say, when I transposed it into Jxta, it quickly became a nightmare to implement.

In theory, it is feasible to modify the rtp/rcp to use another transport protocol, such as Jxta, instead of UDP.

Jxta, although using TCP/HTTP, behaves much like UDP. It became clear to me that if I proxied UDP over Jxta, it would save me from modifying rtp/rcp, still a difficult prospect. Plus I'd have all the UDP protocols at my disposal.

Coupled with proxying TCP as well, it is then theoretically feasible to use anything over Jxta.

Scope of this project

This projects is a Java package to proxy UDP datagrams over Jxta and back. It assumes that the peers running this package will use the localhost address at both ends and, of course, Jxta.

Proxying UDP for other hosts is better dealt with by some new form of routing and/or addressing schemes, to be done in (a) separate project(s).

Package introduction

My first reflex was to extend the java.net.DatagramPacket. Unfortunately, this class is final. It is however possible to provide another implementation. The implementation interface turned to be too much UDP transport oriented to my taste. So the class Convert (see below) with 4 static methods to convert datagrams to Jxta message representation and forth.

The java.net.DatagramSocket is not final. In a first implementation, the JxtaDatagramSocket directly extended the java.net.DatagramSocket. I wanted however to have the JxtaDatagramSocket class to behave as much like the java.net.DatagramSocket and vice versa. But in Jxta, it is possible to receive messages asynchronously as well as synchronously.

In the current implementation, UDPDatagramSocket extends java.net.DatagramSocket in order to add asynchronous packets reception and JxtaDatagagramSocket then extends the UDPDatagramSocket.

It turns out that this approach make writing the rest of the package much simpler.

The library is event based. No single class does a complete useful job. They are meant to be used in a plug-in way. Some classes are not used (yet) and may thus appear to be redundant. They are however part of this package, because they are a possible answer to the implementation problems I met.

See the Package content for more descriptions.

With this package, I will try again to send video over Jxta.

Project name, category and licence

Unless it collides with an already taken name, the name of this project is "vUjxDP: UDP via Jxta (not Jxta over UDP)". This project will be put in the "forge" category under the "Sun Project JXTA Software License."

Perspective of this project

The usefulness of this package will of course be enhanced if an UDP transport were added to Jxta, thus saving a TCP or worse HTTP detour.

Package content

be.loah.udp.event

DatagramAvailableEvent
Event used to encapsulate a Datagram and the protocol used to generate it.
DatagramAvailableListener
Interface to be implemented by classes wishing to process a DatagramAvailableEvent.

be.loah.udp.datagram

Convert
This class contains static methods to convert DatagramPackets into Messages and vice versa.
UDPDatagramSocket
A DatagramSocket with asynchronous DatagramPacket input detection.
JxtaDatagramSocket
This class extends the UDPDatagramSocket in order to be used in its place. his makes it possible to ignore the fundamental differences between UDP and Message transports.
Server
This class implements an UDPDatagramSocketServer. It knows how to receive DatagramPackets, but leave the processing to classes implementing the DatagramAvailableListener interface. The server receives DatagramPackets asynchronously.
UDPproxy
Convenience class that resends a DatagramPacket. This class can be used as is or as a base to implement a DatagramAvailableListener.

be.loah.jxta.util

FilePipeAdvertisement
Convenience class to construct a PipeAdvertisement from a corresponding XML file.
JxtaConnector
Threaded class used to get an InputPipe and an OutputPipe given a PeerGroup and a PipeAdvertisement. Uses a JxtaServerPipe and a JxtaBiDiPipe internally.
PipeFactory
Convenience class used to create input and output pipe.

be.loah.udp.session

Session
A Session Object must implement this interface.
SessionEvent
Event used to indicate a change in a Session.
SessionListener
Objects wanting to process SessionEvent must implement this interface.
AbstractSession
This abstract class represents a Session created when a Client calls a Server.
SimpleSession
Example of a simple session object.

Michel Polet
22 March 2006

/Files/cuizhf/vujxdp.zip
——————————————————————————————————
傲轩游戏网
原文地址:https://www.cnblogs.com/cuizhf/p/2251663.html