Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- import java.util.*;
- public class Client {
- final static int server_port = 9000;
- final static String ip = "localhost";
- static int pass = -1;
- public static void main(String[] args) throws IOException {
- Scanner sc = new Scanner(System.in);
- Socket socket = new Socket(ip, server_port);
- DataInputStream input = new DataInputStream(socket.getInputStream()); // toa sto go pecati serverot
- DataOutputStream output = new DataOutputStream(socket.getOutputStream()); // toa sto nie go pecatime na serverot
- Thread prati_poraka = new Thread(new Runnable() {
- @Override
- public void run() {
- while (true) {
- String s = sc.nextLine();
- try {
- output.writeUTF(s);
- output.flush();
- }
- catch (IOException ex) {
- ex.printStackTrace();
- }
- if(pass == -1) {
- pass = 1;
- s = sc.nextLine();
- try {
- output.writeUTF(s);
- output.flush();
- }
- catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- }
- });
- Thread primi_poraka = new Thread(new Runnable() {
- @Override
- public void run() {
- while(true) {
- try {
- String s = input.readUTF();
- if (s.equals("Login failed!")) {
- System.out.println("Login failed... Try again...");
- System.exit(0);
- }
- System.out.println(s);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- });
- prati_poraka.start();
- primi_poraka.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement