-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,334 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Void> clearstatus = new Service<Void>() | ||
{ | ||
public Task<Void> createTask() | ||
{ | ||
return new Task<Void>() | ||
{ | ||
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?import javafx.scene.control.*?> | ||
<?import javafx.geometry.*?> | ||
<?import javafx.scene.layout.*?> | ||
|
||
|
||
|
||
<GridPane xmlns:fx="http://javafx.com/fxml" prefWidth="500" prefHeight="300" hgap="20" vgap="20" alignment="center" fx:controller="intranet.source.client.controller.LoginController"> | ||
<Label text="Your Name: " GridPane.columnIndex="0" GridPane.rowIndex="0"/> | ||
<TextField fx:id="yname" promptText="Your Name" GridPane.columnIndex="1" GridPane.rowIndex="0"/> | ||
|
||
<Button text="submit" prefHeight="30" prefWidth="200" GridPane.columnIndex="1" GridPane.rowIndex="3" fx:id="submitbutton" onAction="#joinChat" defaultButton="true"/> | ||
|
||
<Label text="" fx:id="status" GridPane.columnIndex="0" GridPane.rowIndex="5" GridPane.columnSpan="3" /> | ||
</GridPane> |
Oops, something went wrong.