Hi, i would like to add 2 methods. Username and password. Client enter the username into the command line and server saves it. Then client enter the password. The password should be sum of ASCII values from the username. Finally the server should make a control and if the password equals the ASCII sum, it should by everything OK and server can do some other stuff.
Do you have any idea how i can add these two methods ? Thank you !
public class Server extends Thread { StringBuilder sb = new StringBuilder(); int indicator = 0; Socket socket; String name = ""; String password = ""; public static void main(String[] args) { try { ServerSocket ss = new ServerSocket(3618); while (true) { Socket s = ss.accept(); Server srv = new Server(); srv.socket = s; srv.start(); } } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } } @Override public void run() { try { String str = ""; int chars; int ch = 0; PrintWriter out = new PrintWriter(socket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); while ((chars = in.read()) != -1) { sb.append((char) chars); str = sb.toString(); } } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } } void sendMessage(String message, PrintWriter pw) { pw.write(message); pw.flush(); }