Package cleancoderscom.tests.utilities

Source Code of cleancoderscom.tests.utilities.HelloWorld

package cleancoderscom.tests.utilities;

import cleancoderscom.socketserver.SocketServer;
import cleancoderscom.socketserver.SocketService;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class HelloWorld implements SocketService {
  public static void main(String[] args) throws Exception {
    SocketServer server = new SocketServer(8080, new HelloWorld());
    server.start();
  }

  @Override
  public void serve(Socket s) {
    try {
      OutputStream os = s.getOutputStream();

      String response = "HTTP/1.1 200 OK\n" +
          "Content-Length: 21\n" +
          "\n" +
          "<h1>Hello, world</h1>";

      os.write(response.getBytes());
    } catch(IOException e) {
      e.printStackTrace();
    }
  }
}
TOP

Related Classes of cleancoderscom.tests.utilities.HelloWorld

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.