mercredi 13 mai 2015

Selector gibt nichts zurück

Hallöchen,

ich schreibe gerade an einem Netzwerkcode bzw. an dem Server.
Mein Problem besteht darin, dass ich zwei Selector erstellt habe mit 2 SelectionKeys.
Wenn ich jetzt aber einen Channel registrieren lassen, bekomme ich in keinem Falle etwas zurück,
außer die Connection wurde bereits beendet ( IDK ). Ich wäre glücklich, wenn mir jemand den Fehler zeigen könnte.

Java 8 : 1.8.0 45-b14

Java Code:

  1. package neogc.net.network.runtime;
  2.  
  3. import java.io.IOException;
  4. import java.nio.channels.ClosedChannelException;
  5. import java.nio.channels.SelectionKey;
  6. import java.nio.channels.Selector;
  7. import java.nio.channels.SocketChannel;
  8. import java.util.Set;
  9.  
  10.  
  11. public class Distributor {
  12.  
  13. private final Selector rs, ws;
  14.  
  15. public Distributor() throws IOException {
  16. rs = Selector.open();
  17. ws = Selector.open();
  18. }
  19.  
  20. public void addChannel(SocketChannel channel) throws ClosedChannelException {
  21. channel.register(rs, SelectionKey.OP_READ);
  22. channel.register(ws, SelectionKey.OP_WRITE);
  23. }
  24.  
  25. public Set<SelectionKey> nextReadChannels() throws IOException {
  26. System.out.println(rs.select(3L));
  27. return rs.selectedKeys();
  28. }
  29.  
  30. public Set<SelectionKey> nextWriteChannels() throws IOException {
  31. ws.select(3L);
  32. return ws.selectedKeys();
  33. }
  34.  
  35.  
  36. }


Mfg,
Thalion


Selector gibt nichts zurück

0 commentaires:

Enregistrer un commentaire