2014-01-06 2 views
-1

서버는 스레드를 사용하여 여러 연결을 허용합니다.간단한 소켓 통신 프로그램이 전혀 작동하지 않습니다.

서버 :

@Override 
public void run() { 
    try { 
     System.out.println(client); 
     System.out.println("Client Connected"); 
     //So far, so good. Client is connected 

     BufferedReader in = new BufferedReader(
       new InputStreamReader(this.client.getInputStream())); 
     System.out.println(in.readLine()); 
     // Nothing happens 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

} 

클라이언트 :

try { 
     PrintWriter out = new PrintWriter(Client.socket.getOutputStream()); 
     BufferedReader in = new BufferedReader (
       new InputStreamReader(Client.socket.getInputStream())); 

     out.write("Information sent from client"); 
     // Does not work 
     in.read(); 
     // Before this .read it would give a "Connection reset" probably 
     // Because the client closed before the server could even read 
    } 

오류 없음,하지만 그냥 달려, 아무것도 전송되지되고있다. 방화벽이 다운되어서 그렇게 할 수 없습니다. 어제도 일 했었습니다. 내가 뭘 망칠 수 있었는지 전혀 모른다.

+0

net cat을 사용하여 클라이언트와 서버를 각각 교체하여 어떤 작품이 보였습니까? – 735Tesla

+0

'readline()'은 문서마다 개행을 사용합니다. 당신은 하나를 보내지 않아 막히고 결코 돌아 오지 않을 것입니다. –

답변

2

writeInputStream에만 내용을 씁니다. println을 사용하여 서버의 readLine 문에 해당하는 줄 바꿈 문자를 추가로 보냅니다.

out.println("Information sent from client"); 
+0

아, 개행 문자가 없으므로 서버가 하나가 올 때까지 대기합니다 (결코 그렇지 않을 것입니다)? 고맙습니다. 공장. – Kalec

관련 문제