diff --git a/Client.java b/Client.java new file mode 100644 index 0000000..81e6338 --- /dev/null +++ b/Client.java @@ -0,0 +1,63 @@ +import java.net.Socket; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.util.Scanner; + +class Client +{ + + public static void main(String[] args) { + try + { + + Socket s = new Socket("127.0.0.1",4005); + Scanner scan = new Scanner(System.in); + DataInputStream dis = new DataInputStream(s.getInputStream()); + DataOutputStream dos = new DataOutputStream(s.getOutputStream()); + System.out.println(dis.readUTF()); + dos.writeUTF(scan.nextLine()); + System.out.println(dis.readUTF()); + dos.writeUTF(scan.nextLine()); + new Thread(new Runnable() + { + public void run() + { + while(true) + { + try + { + dos.writeUTF(scan.nextLine()); + } + catch(Exception e) + { + + } + + } + } + }).start(); + new Thread(new Runnable() + { + public void run() + { + while(true) + { + try + { + System.out.println(dis.readUTF()); + } + catch(Exception e) + { + + } + } + } + }).start(); + + } + catch(Exception e) + { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/ConnectedClients.java b/ConnectedClients.java new file mode 100644 index 0000000..34920f0 --- /dev/null +++ b/ConnectedClients.java @@ -0,0 +1,45 @@ +package intranet.source.users; + +import java.net.Socket; +import java.io.DataOutputStream; +import java.io.DataInputStream; + +public class ConnectedClients +{ + private Socket client; + private DataInputStream dis; + private DataOutputStream dos; + private String name; + + public ConnectedClients(String name,Socket client,DataInputStream dis,DataOutputStream dos) + { + this.name = name; + this.client = client; + this.dis = dis; + this.dos = dos; + } + + public Socket getSocket() + { + return this.client; + } + + public String getName() + { + return this.name; + } + + public DataOutputStream getoutputstream() + { + return this.dos; + } + + public DataInputStream getinputstream() + { + return this.dis; + } + public boolean equals(Object o) + { + return (o instanceof ConnectedClients) && (((ConnectedClients)o).name.equals(name)); + } +} \ No newline at end of file diff --git a/LoginController.java b/LoginController.java new file mode 100644 index 0000000..ebecb1c --- /dev/null +++ b/LoginController.java @@ -0,0 +1,86 @@ +package intranet.source.client.controller; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.event.ActionEvent; +import javafx.concurrent.Task; +import javafx.concurrent.Service; +import javafx.concurrent.WorkerStateEvent; +import java.net.Socket; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import javafx.application.Platform; +import intranet.source.client.loader.UILoader; + +public class LoginController +{ + @FXML private Button submitbutton; + @FXML private TextField yname; + @FXML private Label status; + private Socket client; + + public LoginController() + { + try + { + client = new Socket("127.0.0.1",4005); + } + catch(Exception e) + { + System.out.println("Error occurred"); + } + } + + public void joinChat(ActionEvent e) + { + String yName = yname.getText(); + if (yName.isEmpty() || !yName.matches("([a-z]|[A-Z])+")) + { + status.setText("Text should contain alphabets, no space and no numbers"); + clearStatus(); + return; + } + System.out.println("in join chat"); + UILoader.getObject().openChatBox(yName,client); + System.out.println("Method called in UILoader"); + } + + Service clearstatus = new Service() + { + public Task createTask() + { + return new Task() + { + protected Void call() + { + try + { + Thread.sleep(3000); + }catch(Exception e) + { + e.printStackTrace(); + } + Platform.runLater(new Runnable() + { + public void run() + { + status.setText(""); + } + }); + return null; + } + }; + } + }; + + public void clearStatus() + { + if(!clearstatus.isRunning()) + { + clearstatus.reset(); + clearstatus.start(); + } + } +} \ No newline at end of file diff --git a/LoginInterface.fxml b/LoginInterface.fxml new file mode 100644 index 0000000..75cecbe --- /dev/null +++ b/LoginInterface.fxml @@ -0,0 +1,15 @@ + + + + + + + + +