UDP Client/Server

Jiang Bian timobj at gmail.com
Mon Jun 1 00:58:57 EDT 2009


Cool, thanks. And I saw your answer about  NIO UDP in the issue log.
Thanks,

Jiang

On Sun, May 31, 2009 at 11:18 PM, Trustin Lee (via Nabble)
<ml-user+57722-852313764 at n2.nabble.com> wrote:
> Please note that UDP is a connectionless transport.  Your channel did
> bind but didn't connect to a remote address, so
> Channel.getRemoteAddress() will return null because it's not connected
> at all.  It's exactly same with how java.net.DatagramSocket works.  Once
> packet is received, it does have an information about where it came from
> so that we know the remote address from the MessageEvent.
>
> And thanks for reporting the issue with OioDatagramChannel.connect().
> I've just checked in the fix:
>
>   * https://jira.jboss.org/jira/browse/NETTY-163
>
> Trustin
>
> On 31-May-2009 07:07, Jiang Bian wrote:
>>
>> 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
>>>
>>>
>>>
>>>
>>>
>>
>
>
> _______________________________________________
> netty-users mailing list
> netty-users at ...
> https://lists.jboss.org/mailman/listinfo/netty-users
>
> signature.asc (266 bytes) Download Attachment
> Trustin Lee, Principal Software Engineer, JBoss, a division of Red Hat
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
>
> ________________________________
> This email is a reply to your post @
> http://n2.nabble.com/UDP-Client-Server-tp2999122p3004533.html
> You can reply by email or by visting the link above.
>
>

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





More information about the netty-users mailing list