현재 netty.I를 사용하여 채팅 서비스를 만들려고하고 있습니다. 일부 소스 코드에서 내 참조를 가져 왔고 간단한 GUI를 구현하고 싶습니다. 서버 쪽에서 " 보내기 "를 클릭해야 메시지를 클라이언트로 다시 보낼 수 있습니다. 기본적으로 내 MessageReceived 채널 핸들러에 ActionListener를 구현하려고하지만, 최종 변수가 참조가 될 수 없다는 문제로 인해 클라이언트에서 채널을 사용하여 내 메일을 다시 쓸 수 없으므로 몇 가지 문제가 발생합니다. 다른 방법으로 정의 된 내부 클래스에 있습니다.이 문제를 극복하기위한 조언이 필요합니다. 모두 친절한 도움을 요청합니다!netty 채팅 서버 쪽에서 GUI를 올바르게 구현하는 방법
ServerHandler messageReceived 코드 :
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)throws Exception {
System.out.println("Received message from client: " + e.getMessage());
String msgclient = (String) e.getMessage();
ta.append("[From Client]" + msgclient + "\n");
Channel c = e.getChannel();//can't declare it as final also,make no sense
bt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent a){
if(a.getSource()==bt){
String serversentence=tf.getText();
ta.append("[Server]" + serversentence + "\n");
c.write(serversentence + "\n\r");
if (serversentence.toLowerCase().equals("shutdown"))
shutdown();
tf.setText(null);
}
}
});
}