2014-02-17 4 views
0

이 문제는 대중적인 것으로 보이지만 문제 해결에 많은 시간을 할애하여 문제를 해결하는 데 어려움이 있습니다. 업데이트 된 솔루션이 있기를 바랍니다.KryoNet : 연결 후 클라이언트의 연결이 즉시 끊깁니다.

저는 KryoNet Java 네트워킹 라이브러리로 간단한 서버와 클라이언트를 설정하고 있습니다. 내 문제는 내 클라이언트가 서버에 연결 한 후 즉시 연결을 끊는 것입니다.

서버

public class TheServer extends Listener { 

    static Server server; 
    static final int PORT = 8215; 

    public static void main(String[] args) throws IOException { 
     server = new Server(); 
     server.start(); 
     server.bind(PORT); 
     server.addListener(new TheServer()); 
     System.out.println("server started on " + PORT); 
    } 

    public void connected(Connection c) { 
     System.out.println("connected: " + c.getID()); 
    } 

    public void disconnected(Connection c) { 
     System.out.println("disconnected: " + c.getID()); 
    } 

} 

클라이언트 다음 TheServerTheClient를 실행 한 후

public class TheClient extends Listener { 

    static Client client; 
    static final String IP = "localhost"; 
    static final int PORT = 8215; 

    public static void main(String[] args) throws IOException { 
     client = new Client(); 
     client.start(); 
     client.connect(5000, IP, PORT); 
     client.addListener(new TheClient()); 
     //client.setKeepAliveTCP(2000); 
    } 

} 

, 내 콘솔 인쇄 :

여기

내 코드입니다
server started on 8215 
connected: 1 
disconnected: 1 

연결과 연결 해제 사이의 시간은 거의 즉각적으로 설정 시간보다 짧습니다. 또한 내가 setKeepAliveTCP() 메서드를 주석 처리했음을 유의하십시오. 필자는 필자가 필요하다고 생각하지는 않지만 삽입하여 작동하는지 확인했기 때문입니다.

new Thread(client).start()

대신

client.start()

수정 문제

의 :

답변

2

digging around 좀 더 후, 나는 함께 클라이언트를 시작하는 것을 발견했다.

"클라이언트 업데이트 스레드가 데몬 스레드로 만들어져 초기화가 완료되면 하위 프로세스가 닫히는 원인이됩니다."

+0

때때로이 aswell 작동하지 않습니다 .. 모든 당신의 registerred 클래스는이 prefectly했다 그들에 빈 생성자, https://github.com/EsotericSoftware/kryonet/issues/35 – Makerimages

+0

이 있어야합니다! 고맙습니다 –

관련 문제