I am trying creating a socket connection to a web server.
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");
}
}
}
The client request con = svrSocket.accept();
does not run. I say this because the message after this line does not display.
Why does it not accept the client request and is it possible to test the Server using a Web browser? Please excuse my bad programming style.
Thank you.