1 ImportJava.io.PrintStream;2 ImportJava.net.Socket;3 ImportJava.net.ServerSocket;4 ImportJava.util.Scanner;5 6 Public classServer7 {8 Public Static voidMain (string[] args)9 throwsExceptionTen { OneServerSocket SS =NewServerSocket (30000); ASocket socket =ss.accept (); -PrintStream PS =NewPrintStream (Socket.getoutputstream ()); -Ps.println ("The first row of data for the server"); thePs.println ("Second row of data for server"); - //closes the output stream of the socket, indicating that the output data has ended - socket.shutdownoutput (); - //The following statement outputs false to indicate that the socket has not been closed. + System.out.println (socket.isclosed ()); -Scanner scan =NewScanner (Socket.getinputstream ()); + while(Scan.hasnextline ()) A { at System.out.println (Scan.nextline ()); - } - scan.close (); - socket.close (); - ss.close (); - } in}View Code
Running the above code, the following error occurred:
ServerSocket ss = new ServerSocket (30000);//error in this line, indicating that 30000 port is occupied, because there may be a program in the occupied 30000 port, you can change the end of the oral test!
Exception in thread "main" java.net.BindException:Address already in Use:jvm_bind