웹 서버에 대한 소켓 연결을 만들려고합니다.서버 소켓으로 클라이언트 요청 수락
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Connection{
public final static int PORT = 1337;
public Connection(){
ServerSocket svrSocket = null;
try{
svrSocket = new ServerSocket(PORT);
System.out.println("Conected to: " + PORT);
Socket con = null;
while(true)
{
try{
con = svrSocket.accept();//on this part the program stops
System.out.println("Client request accepted");
PrintWriter out = new PrintWriter(con.getOutputStream());
out.flush();
}catch(IOException ex)
{
ex.printStackTrace();
}
}
}catch(IOException ex)
{
System.err.println(ex);
System.out.println("Unable to attach to port");
}
}
}
클라이언트 요청 con = svrSocket.accept();
이 실행되지 않습니다. 이 줄 뒤에있는 메시지가 표시되지 않기 때문에 나는 이것을 말한다.
왜 클라이언트 요청을 받아들이지 않고 웹 브라우저를 사용하여 서버를 테스트 할 수 있습니까? 제발 나쁜 프로그래밍 스타일을 용서해주십시오.
감사합니다.
는'svrSocket.accept()가'차단 호출입니다 사용하여 연결합니다. 서버에 연결하기 – Reimeus