[Red5devs] flash java client

Luke Hubbard (luke@codegent.com) king.selassie at gmail.com
Mon Feb 27 11:56:26 EST 2006


Hi Guys,

I think we should get together people interested in creating a client.

I did some refactoring over the weekend (not in 0.3) which should make
it easier. In 0.3 we switched to mina 0.9 and its a little different
the way you define the codec. The codec state is now stored in an RTMP
object and can be set to client or server mode.

The Handskake object was removed from svn since it was not actually
used in the code. It isnt really an rtmp packet either since it doenst
have a datatype. The way to handle it echo any bufferers recieved in
the handler.

if(in instanceof ByteBuffer){
	rawBufferRecieved(session, (ByteBuffer) in);
	return;
}

private void rawBufferRecieved(IoSession session, ByteBuffer in) {
	
	final RTMP rtmp = (RTMP) session.getAttribute(RTMP.SESSION_KEY);
	final Connection conn = (Connection) session.getAttachment();
	
	if(rtmp.getState() != RTMP.STATE_HANDSHAKE){
		log.warn("Raw buffer after handshake, something odd going on");
	}
	
	ByteBuffer out = ByteBuffer.allocate((Constants.HANDSHAKE_SIZE*2)+1);
	
	if(log.isDebugEnabled()){
		log.debug("Writing handshake reply");
		log.debug("handskake size:"+in.remaining());
	}
	
	out.put((byte)0x03);
	out.fill((byte)0x00,Constants.HANDSHAKE_SIZE);
	out.put(in).flip();
	session.write(out);
}

The logic inside rawBufferRecieved will different from the client but
the concept is the same.

To create a client connection the code would look something like this
( this code is ripped from DebugProxyHandler ) ...

SocketConnector connector = new SocketConnector();
RTMPClientHandler handler = new RTMPClientHandler();
ConnectFuture future = connector.connect(socketAddress, handler);
future.join(); // wait for connect, or timeout

The RTMPClientHandler would looks like ..

public void sessionCreated(IoSession session) throws Exception {	
	session.setAttribute(RTMP.SESSION_KEY,new RTMP(RTMP.MODE_CLIENT));
}
		
public void sessionOpened(IoSession session) throws Exception {
        // once the connection is open, send the initial handshake data.
}

I hope this helps. Gotta run.

-- Luke

On 2/27/06, Moreno Balcon <mbalcon at h-care.it> wrote:
> Hi,
>
> I'm try to use red5 to make a java client too... but just now, with last
> checkout... i see that the Handshake object are deleted
> from the repository :(
>
> ... i don't know why... but without it i think must be create a new
> object for simulate it...
>
>
>
>
> Lorenzo Sicilia ha scritto:
> > Alle 18:45, lunedì 20 febbraio 2006, Lorenzo Sicilia ha scritto:
> >
> >> Any  info about the Red classes that I must study would be very appreciate
> >> Can you tell me the classes that handle:
> >> - openSession
> >> - sending rtmp message
> >> - reading rtmp message
> >> And last but not the list  Is it supported Connection.MODE_CLIENT?
> >>
> >
> > I get 0.3 release from svn and it works nice. Good work guys!
> >
> > I don't found any improvement around Connection.MODE_CLIENT
> > I would like to know if MODE_CLIENT works or if at the moment it's an idea.
> > Do you think that with Red5 Api (0.3) I can write a client?
> >
> > Thanks in advance.
> >
> > Regards Lorenzo
> >
> > _______________________________________________
> > Red5devs mailing list
> > Red5devs at osflash.org
> > http://osflash.org/mailman/listinfo/red5devs_osflash.org
> >
> >
> >
>
>
> --
> Moreno Balcon           email: mbalcon at h-care.it
> http://www.h-care.it    aim: moreno.balcon at mac.com
>
>
>
>
> _______________________________________________
> Red5devs mailing list
> Red5devs at osflash.org
> http://osflash.org/mailman/listinfo/red5devs_osflash.org
>



More information about the Red5devs mailing list