Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main (String[] args){
- try (Socket socket = new Socket("localhost", 80);
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "US-ASCII"), 100000000);) {
- StringBuilder sb = new StringBuilder();
- //Communication works fine with i<1000000
- for (int i=0; i<10000000; i++) {
- sb.append("a");
- }
- String output = "GET / " + sb.toString() + " HTTP/1.1" + "rn";
- writer.write(output, 0, output.length());
- writer.flush();
- InputStream is = socket.getInputStream();
- System.out.println((char) is.read());
- } catch (IOException e) {
- e.printStackTrace(System.out);
- }
- }
- @Override
- public Void call() throws IOException {
- try {
- OutputStream out = new BufferedOutputStream(
- connection.getOutputStream()
- );
- InputStream in = new BufferedInputStream(
- connection.getInputStream()
- );
- // read the first line only; that's all we need
- StringBuilder request = new StringBuilder(80);
- while (true) {
- int c = in.read();
- if (c == 'r' || c == 'n' || c == -1) break;
- request.append((char) c);
- }
- // If this is HTTP/1.0 or later send a MIME header
- if (request.toString().indexOf("HTTP/") != -1) {
- out.write(header);
- }
- out.write(content);
- out.flush();
- } catch (IOException ex) {
- logger.log(Level.WARNING, "Error writing to client", ex);
- } finally {
- connection.close();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement