2013年10月5日星期六

Asynchronous communication methods seek multicast (MulticastChannel)! ! !


// join multicast group on this interface, and also use this
     // interface for outgoing multicast datagrams
     NetworkInterface ni = NetworkInterface.getByName("hme0");

     DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)
         .setOption(StandardSocketOptions.SO_REUSEADDR, true)
         .bind(new InetSocketAddress(5000))
         .setOption(StandardSocketOptions.IP_MULTICAST_IF, ni);

     InetAddress group = InetAddress.getByName("225.4.5.6");

     MembershipKey key = dc.join(group, ni);


This is a copy from the javadoc on the sample code. Not how to read, especially in the first two . . . Explain it. . .

I want to use nio package asynchronous communication model to achieve the multicast client receiving , rather than the traditional model . This should save the client the resources , not been in a listening state ! Is that right ? ? ? ( I use the traditional listening mode , a computer server and open a two clients , cpu can reach 60% of the == . )

discovered behind jdk 7 in multicastChannel should be able to achieve what I want to achieve, but do not know how to use , seeking advice. . .
------ Solution ---------------------------------------- ----
JDK 7 there are cases in the sample , so why do not you check ?

in JDK 7 sample of nio \ multicast directory.

JDK 7 's demo and sample be downloaded here:
http://www.oracle.com/technetwork/java/javase/downloads / index.html
------ For reference only ------------------------------ ---------
master, come around this time that the jar up . . .
------ For reference only -------------------------------------- -
did not care . . . . . I'll hang == .
------ For reference only -------------------------------------- -
the problem is how it was. . . Reaction to the point ah == . Whining -----
------ For reference only ------------------------------- --------
did not get off , but there api can check oh.
java.net.NetworkInterface.java
java.nio.channels.DatagramChannel.java
------ For reference only ------------------------- --------------
you mean you look at the source - . . . My jdk Chinese version is 1.6 with no content in this area . . . Eggs broken
------ For reference only ----------------------------------- ----
you use TCP SocketChannel will use it ? It is like this is also used by the Selector register event

By DatagramChannel # send send data , receive data via DatagramChannel # receive chant
------ For reference only -------------- -------------------------
SocketChannel operator will use it. . . Oh, the critical time , there is the old coming out !

first few weeks at school socketChannel when you asked a lot of questions ~
------ For reference only ------------------- --------------------
I have tried to follow that logic nio wrote , but failed. . .
------ For reference only -------------------------------------- -
Oh, ah , let me see say , thank you ha ! Think about loneliness in my sleep before actually able to receive such exciting news , moved ing
fought ! ! !
------ For reference only -------------------------------------- -
Come on, come
------ For reference only --------------------------------------- < br> this is the landlord of JDK7
look JDK7 the API
------ For reference only ----------------------------- ----------
landlord, you did not get to know , I have encountered this problem seek QQ. My QQ is 1031248990

没有评论:

发表评论