< prev index next >

src/java.base/share/classes/sun/net/NetworkServer.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 25,34 **** --- 25,35 ---- package sun.net; import java.io.*; import java.net.Socket; import java.net.ServerSocket; + import jdk.internal.io.IOSupport; /** * This is the base class for network servers. To define a new type * of server define a new subclass of NetworkServer with a serviceRequest * method that services one request. Start the server by executing:
*** 115,131 **** clientOutput streams initialized. This method handles one client connection. When it is done, it can simply exit. The default server just echoes it's input. It is invoked in it's own private thread. */ public void serviceRequest() throws IOException { - byte buf[] = new byte[300]; - int n; clientOutput.print("Echo server " + getClass().getName() + "\n"); clientOutput.flush(); ! while ((n = clientInput.read(buf, 0, buf.length)) >= 0) { ! clientOutput.write(buf, 0, n); ! } } public static void main(String argv[]) { try { new NetworkServer ().startServer(8888); --- 116,128 ---- clientOutput streams initialized. This method handles one client connection. When it is done, it can simply exit. The default server just echoes it's input. It is invoked in it's own private thread. */ public void serviceRequest() throws IOException { clientOutput.print("Echo server " + getClass().getName() + "\n"); clientOutput.flush(); ! IOSupport.copy(clientInput, clientOutput, 300); } public static void main(String argv[]) { try { new NetworkServer ().startServer(8888);
< prev index next >