public static void main(String[] args) throws Exception { if (args.length != 4) { System.out.println("Usage: SampleServer <keystore> <password> <root file> <port>"); return; } String keystoreFile = args[0]; String password = args[1]; String root = args[2]; int port = Integer.parseInt(args[3]); SSLContext sslContext = sslContext(keystoreFile, password); SampleServer server = new SampleServer(sslContext, root, port); server.run(); }
public class Main { public static void main(String[] args) throws Exception { //Create a server //Server has to be only one and multiple clients can connect it SampleServer server = new SampleServer(5555); server.startServer(); //Creating one client Socket soc = new Socket("localhost", 5555); //Similarly create n-number of clients and connect to the same port as that of server //server.getClientList(); will help you get the list of the clients connected to the server } }
private MockResponse fileToResponse(String path, File file) throws IOException { return new MockResponse() .setStatus("HTTP/1.1 200") .setBody(fileToBytes(file)) .addHeader("content-type: " + contentType(path)); }
@Override public MockResponse dispatch(RecordedRequest request) { String path = request.getPath(); try { if (!path.startsWith("/") || path.contains("..")) throw new FileNotFoundException(); File file = new File(root + path); return file.isDirectory() ? directoryToResponse(path, file) : fileToResponse(path, file); } catch (FileNotFoundException e) { return new MockResponse() .setStatus("HTTP/1.1 404") .addHeader("content-type: text/plain; charset=utf-8") .setBody("NOT FOUND: " + path); } catch (IOException e) { return new MockResponse() .setStatus("HTTP/1.1 500") .addHeader("content-type: text/plain; charset=utf-8") .setBody("SERVER ERROR: " + e); } }