My professor gave me this TCP / UDP example and he said that it worked for him. However, when I am going to compile, I get an exclusion API error, which states that the reading line is no longer in use ...
How can I handle it?
Code:
Import java.io. *; Import Java.net *; Public class server {static socket client socket = zero; Static server secet server server = null; // This chat server can accept the connection of 10 clients to a static clientTrade T [] = New client thread [10]; Public static zero main (string array []) {// default port in port_number = 2222; If (args.length & lt; 1) {System.out.println ("Use: Java MultitradeCat Server \ n" + "now using Port Number =" + port_number); } Other {port_number = integer.valuef (args [0]). IntValue (); } Try {ServerSocket = new ServerSocket (port_number); } Hold (IOException e) {System.out.println (e);} while (true) {try {clientSocket = serverSocket.accept (); (Int i = 0; i & lt; = 9; i ++) {if (t [i] == faucet) {(t [i] = new client thread (client socket, t)). break; }}} Hold (IOException e) {System.out.println (e);}}}} Class Client Thread Extended Thread {DataInputStream is = null; Printstream OS = null; Socket client socket = empty; Client threads []; Public client thread (socket client socket, client thread [] t) {this.clientSocket = clientSocket; This.t = t; } Public Zero Run () {String Line; String name; Try {New DataInputStream (clientSocket.getInputStream ()); OS = new printstream (clientSocket.getOutputStream ()); Osprintln ("Enter your name."); Name = is.readLine (); Osprintln ("Hello" + name + "to enter. \ N in our chat room / to leave in a new line"); For (int i = 0; i & lt; = 9; i ++) if (t [i]! = Null & t [i]! = This) t [i] .os.printLN ("* ** A new user "+ name +" was entered in the chat room !!! ***); Whereas (true) {line = is.readLine (); If (with line star ("left /") break; For (int i = 0; i & lt; = 9; i ++) if (t [i]! = Null) t [i] .os.println ("& lt;" + name + "& gt; "+ Line); } (Int i = 0; i & lt; = 9; i ++) if (t [i]! = Null & t [i]! = This) t [i] .os.println (" *** User "+ name +" is leaving the chat room !!! *** "); Osprintln ("*** goodbye" + name + "***"); For (int i = 0; i & lt; = 9; i ++) if (t [i] == this) t [i] = null; is close(); Os.close (); ClientSocket.close (); } Hold (IOException e) {}; }} There is only one thing in the client class.
I'm thinking that you want to know what you should use instead? The Java API document states that you should use
Comments
Post a Comment