Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package clientcoursework2;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- /**
- *
- * @author User
- */
- public class Login {
- public int port = 1234;
- //public String ip = null;
- public Socket login = null;
- public PrintWriter outStream = null;
- private BufferedReader inStream = null;
- private boolean ON = false;
- public String authorize = null;
- public boolean Loginn(String UserName, String PassWord, String IP) throws UnknownHostException, IOException {
- login = new Socket(IP, port);
- //inStream = new BufferedReader(new InputStreamReader(client.getInputStream()));
- //while (!inStream.ready()) {}
- //System.out.println(inStream.readLine()); // Read one line and output it
- outStream = new PrintWriter(login.getOutputStream(), true);
- outStream.println(UserName + " " + PassWord);
- //outStream.close();
- inStream = new BufferedReader(new InputStreamReader(login.getInputStream()));
- authorize = inStream.readLine();
- System.out.println(authorize); // Read one line and output it
- //inStream.close();
- if (authorize.equals("logincomplete"))
- {
- JOptionPane.showMessageDialog(null,"Welcome: " + UserName);
- login.close();
- return true;
- }
- else
- {
- JOptionPane.showMessageDialog(null,"Logged Failed! User '" + UserName + "' Does Not Exist!");
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment