-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
b7c2b12
commit 9008e97
Showing
10 changed files
with
71 additions
and
278 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#Sun, 03 Oct 2021 22:43:46 +0200 | ||
#Thu, 13 Jan 2022 20:10:24 +0100 | ||
|
||
|
||
C\:\\Users\\Anix\\Documents\\Coding\\Java\\Projects\\SocketChatApp= |
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,41 +1,50 @@ | ||
package socketchatapp; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.util.Scanner; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class Client extends Network { | ||
|
||
public Client(String ip, int port) { | ||
this.port = port; | ||
this.ip = ip; | ||
run(); | ||
init(); | ||
} | ||
|
||
public void sendMSG(String msg) { | ||
out.println(msg); | ||
out.flush(); | ||
} | ||
|
||
public void receivedMSG(String msg) { | ||
Main.instance.addMessage("> " + msg); | ||
} | ||
|
||
public void run() { | ||
public void init() { | ||
try { | ||
initSocket(new Socket(ip, port)); | ||
out.println(Main.instance.getNAME()); | ||
new Thread(() -> { | ||
listener(); | ||
run(); | ||
}).start(); | ||
|
||
} catch (IOException ex) { | ||
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); | ||
Main.instance.addMessage("[!] Failed to connect to Server!"); | ||
Main.instance.switchAll(true); | ||
} | ||
} | ||
} | ||
|
||
public void run() { | ||
String res; | ||
Scanner sc = new Scanner(in); | ||
while (sc.hasNextLine()) { | ||
res = sc.nextLine(); | ||
receivedMSG(res); | ||
} | ||
// end of Thread | ||
sc.close(); | ||
Main.instance.addMessage("Disconnected!"); | ||
Main.instance.switchAll(true); | ||
} | ||
|
||
public void sendMSG(String msg) { | ||
out.println(msg); | ||
out.flush(); | ||
} | ||
|
||
public void receivedMSG(String msg) { | ||
Main.instance.addMessage("> " + msg); | ||
} | ||
} |
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
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
Oops, something went wrong.