UDP Client/Server

Jiang Bian timobj at gmail.com
Sat May 30 18:07:38 EDT 2009


Well... it's probably my bad... but I don't really get the reason.
it's ok to use e.getRemoteAddress(), but not
e.getChannel().getRemoteAddress()

Is it because UDP doesn't have a channel?... doesn't really make sense to
me...

Thanks,

Jiang



Jiang Bian wrote:
> 
> <p>
> 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.
> </p>
> <p>
> 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.
> </p>
> The NodeServerHandler extends SimpleChannelHandler, and here is how its
> setup:
> <pre>
>         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));
> </pre>
> 
> Here is the client part:
> <pre>
>         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));
> </pre>
> ...
> 
> sending a request from the client:
> <pre>
>             ChannelBuffer buffer =
> JigDFSProtocolRequestFactory.requestToSendFileSlice(
> 		    fileHash, fileHash, parentNodeID, 1, encryptionKey,
> 		    totalNumber);
> 
> 	    c.write(buffer, new InetSocketAddress(this.toNode
> 		    .getHost(), this.toNode.getPort()));
> </pre>
> 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:
> <pre>
> ChannelBuffer buffer = JigDFSProtocolRequestFactory.ackSaveSliceReq();
> e.getChannel().write(buffer, e.getChannel().getRemoteAddress());
> </pre>
> and the problem is caused by:
> <pre>
> e.getChannel().getRemoteAddress() returns NULL... 
> </pre>
> I can't figure out why it's none... and also, I was trying to do 
> <pre>
> c = (DatagramChannel) b.bind(new InetSocketAddress(0));
> c.connect(new InetSocketAddress(this.toNode
> 		    .getHost(), this.toNode.getPort()));
> </pre>
> <p>but it hangs on the connect() forever...
> I know it's not necessary to connect, but why it doesn't work?
> </p>
> 
> <p>
> I did built my code based on the Quote Sever example...but...
> </p>
> 
> <p>
> Also, I know UDP in netty is not NIO, but is there any plan to have NIO
> UDP in the future and any timelines?
> </p>
> 
> <p>
> Any suggestion will be appreciated! 
> Thanks very much in advance!
> </p>
> Jiang
> 
> 
> 
> 
> 

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




More information about the netty-users mailing list