0
죄송합니다. 시간을 낭비하는 경우 죄송합니다.하지만 Netty (jboss)를 처음 사용하는 순간이며, 내가 무엇을하고 있는지 전혀 알지 못합니다. 여기에 내가 쓰고 싶은 내 서버의 이중 :처음 JBoss Netty를 사용하는 경우
public final class UpdateServer extends SimpleChannelHandler {
private static ChannelGroup channels;
private static final int PORT = 55555;
private static final double VERSION = 1.66;
public static void main(String[] args) {
init();
}
public static final void init() {
new UpdateServer();
}
/*
* throws exeption so if cant handle channel server closes
*/
private UpdateServer() {
ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
ServerBootstrap bootstrap = new ServerBootstrap(factory);
ChannelPipeline pipeline = bootstrap.getPipeline();
pipeline.addLast("handler", this);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.bind(new InetSocketAddress(PORT));
System.out.println("Listening for connections on port: "+PORT);
}
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
channels.add(e.getChannel());
}
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) {
channels.remove(e.getChannel());
}
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
System.out.println("Connected!");
e.getChannel().write(VERSION);
ctx.getChannel().write(VERSION);
}
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
}
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
System.out.println("Message Recieved");
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent ee) throws Exception {
}
}
하지만 난 0.0 읽기, double 값 클라이언트를 실행할 때 : 0.0에서 인쇄 왜
public class UpdateChecker {
public static void main(String[] args) throws Exception {
SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 55555));
socketChannel.configureBlocking(false);
ByteBuffer buffer = ByteBuffer.allocateDirect(8);
socketChannel.read(buffer);
double value = buffer.getDouble();
System.out.println(value);
}
}
는 잘 모르겠어요 그건 내가 쓴 것이 아니기 때문에 어떻게 수정해야합니까?
감사합니다.
스레드를 업데이트했습니다. –