Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
loveofguoke committed Jan 7, 2023
1 parent 1e8f7dd commit 13cf252
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ res
.vscode
*.class
src/client
*.log
*.log
.idea
*.iml
Binary file added docs/P2 ChatServer.pdf
Binary file not shown.
Binary file added docs/nio.pdf
Binary file not shown.
34 changes: 17 additions & 17 deletions src/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ public Client(Selector sel, SocketChannel socket) {

@Override
public void run() {
try {
// String str = in.readLine();
// in.clear();
// socket.read(in);
ByteBuffer in = ByteBuffer.allocate(MAXIN);
socket.read(in);
String str = new String(in.array());
// System.out.println("####1"+str+"####2");
notifyMsgRcvd(str);
if (str.equals("END")) {
System.out.println("closing...");
quit();
}
// System.out.println("Echoing: " + str);
// out.println(str);
} catch (IOException e) {
try {
// String str = in.readLine();
// in.clear();
// socket.read(in);
ByteBuffer in = ByteBuffer.allocate(MAXIN);
socket.read(in);
String str = new String(in.array());
// System.out.println("####1"+str+"####2");
notifyMsgRcvd(str);
if (str.equals("END")) {
System.out.println("closing...");
quit();
}
}
// System.out.println("Echoing: " + str);
// out.println(str);
} catch (IOException e) {
quit();
}
}

synchronized void sendMsg(String line) {
Expand Down

0 comments on commit 13cf252

Please sign in to comment.