Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public static void main (String[] args){
  2. try (Socket socket = new Socket("localhost", 80);
  3. BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "US-ASCII"), 100000000);) {
  4.  
  5. StringBuilder sb = new StringBuilder();
  6. //Communication works fine with i<1000000
  7. for (int i=0; i<10000000; i++) {
  8. sb.append("a");
  9. }
  10.  
  11. String output = "GET / " + sb.toString() + " HTTP/1.1" + "rn";
  12. writer.write(output, 0, output.length());
  13. writer.flush();
  14.  
  15. InputStream is = socket.getInputStream();
  16. System.out.println((char) is.read());
  17. } catch (IOException e) {
  18. e.printStackTrace(System.out);
  19. }
  20. }
  21.  
  22. @Override
  23. public Void call() throws IOException {
  24. try {
  25. OutputStream out = new BufferedOutputStream(
  26. connection.getOutputStream()
  27. );
  28. InputStream in = new BufferedInputStream(
  29. connection.getInputStream()
  30. );
  31. // read the first line only; that's all we need
  32. StringBuilder request = new StringBuilder(80);
  33.  
  34. while (true) {
  35. int c = in.read();
  36. if (c == 'r' || c == 'n' || c == -1) break;
  37. request.append((char) c);
  38. }
  39.  
  40. // If this is HTTP/1.0 or later send a MIME header
  41. if (request.toString().indexOf("HTTP/") != -1) {
  42. out.write(header);
  43. }
  44. out.write(content);
  45. out.flush();
  46. } catch (IOException ex) {
  47. logger.log(Level.WARNING, "Error writing to client", ex);
  48. } finally {
  49. connection.close();
  50. }
  51. return null;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement