UDP Client/Server

Jiang Bian timobj at gmail.com
Sat May 30 12:50:13 EDT 2009



I have been scratching my head off to figure out the problem.
I am writing a distributed file system and trying to use netty's UDP as the
network layer.


Here is my problem:
I have a UDP client send a request (request to send a file including some
basic file information) to the server, and the server should respond with
and ACK.

The NodeServerHandler extends SimpleChannelHandler, and here is how its
setup:

        DatagramChannelFactory f = new OioDatagramChannelFactory(Executors
		.newCachedThreadPool());

	b = new ConnectionlessBootstrap(f);
	ChannelPipeline p = b.getPipeline();
	p.addLast("handler", new NodeServerHandler(this.node));

	b.setOption("broadcast", "false");
	b.setOption("sendBufferSize", 65536);
	b.setOption("receiveBufferSize", 65536);

        b.bind(new InetSocketAddress(this.port));


Here is the client part:

        f = new OioDatagramChannelFactory(Executors.newCachedThreadPool());

	b = new ConnectionlessBootstrap(f);
	ChannelPipeline p = b.getPipeline();
	p.addLast("logger", new LoggingHandler());
	p.addLast("handler", this);
	b.setOption("broadcast", "false");
	b.setOption("sendBufferSize", 65536);
	b.setOption("receiveBufferSize", 65536);

	c = (DatagramChannel) b.bind(new InetSocketAddress(0));

...

sending a request from the client:

            ChannelBuffer buffer =
JigDFSProtocolRequestFactory.requestToSendFileSlice(
		    fileHash, fileHash, parentNodeID, 1, encryptionKey,
		    totalNumber);

	    c.write(buffer, new InetSocketAddress(this.toNode
		    .getHost(), this.toNode.getPort()));

and it does go through and my server handler get the message in
messageReceived function, however, when I try to write back a response it
failed, and I find out the problem is here:

ChannelBuffer buffer = JigDFSProtocolRequestFactory.ackSaveSliceReq();
e.getChannel().write(buffer, e.getChannel().getRemoteAddress());

and the problem is caused by:

e.getChannel().getRemoteAddress() returns NULL... 

I can't figure out why it's none... and also, I was trying to do 

c = (DatagramChannel) b.bind(new InetSocketAddress(0));
c.connect(new InetSocketAddress(this.toNode
		    .getHost(), this.toNode.getPort()));

but it hangs on the connect() forever...
I know it's not necessary to connect, but why it doesn't work?



I did built my code based on the Quote Sever example...but...



Also, I know UDP in netty is not NIO, but is there any plan to have NIO UDP
in the future and any timelines?



Any suggestion will be appreciated! 
Thanks very much in advance!

Jiang




-- 
View this message in context: http://n2.nabble.com/UDP-Client-Server-tp2999122p2999122.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list