import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public class HTTPWorker implements Runnable {
private Socket socket;
public HTTPWorker(Socket socket) {
this.socket=socket;
}
@Override
public void run() {
try(InputStream is=socket.getInputStream();
OutputStream os=socket.getOutputStream();
Scanner sc=new Scanner(is);
PrintWriter pw=new PrintWriter(os,true)){
while(sc.hasNextLine()) {
pw.println("Podaj nazwe serwera:");
String url=sc.nextLine();
pw.println("podaj numer portu:");
if(url!=null) {
String port=sc.nextLine();
int portInt=Integer.parseInt(port);
try(Socket s= new Socket(url,portInt);
InputStream is2=s.getInputStream();
OutputStream os2=s.getOutputStream();
Scanner sc2=new Scanner(is2);
PrintWriter pw2=new PrintWriter(os2)){
pw.println("GET /index.html");
//pw.println("Host: google.com");
//pw.println("Content- Type: text/html");
pw.println("\n");
pw.flush();
while(sc.hasNextLine()) {
System.out.println(">"+sc.nextLine());
}
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}