Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

66 changes: 0 additions & 66 deletions corock/src/main/java/com/cowaine/corock/mission/game/Sender.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.cowaine.corock.mission.game.client;

import com.cowaine.corock.mission.game.io.OutputView;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

/**
* A GameClient is a client that uses the game.
*/
class GameClient {

private final String userId;

GameClient(String userId) {
this.userId = userId;
}

void connect(String serverHost, int port) {
try {
Socket socket = new Socket(serverHost, port);
OutputView.printConnectToServer(serverHost, port);

Thread sender = new Sender(socket, userId);
sender.start();

Thread receiver = new Receiver(socket);
receiver.start();

} catch (UnknownHostException e) {
OutputView.printUnknownHostException(e.getMessage());
} catch (IOException e) {
OutputView.printIoException(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.cowaine.corock.mission.game.client;

import com.cowaine.corock.mission.game.server.ServerConfig;

/**
* Game client in the shell.
*/
public class GameClientShell {

/**
* The main method for playing the game.
*
* @param args The user's ID
*/
public static void main(String[] args) {
if (args.length == 0) {
throw new IllegalArgumentException("게임에 사용할 아이디를 설정해주세요.");
}

String userId = args[0];
GameClient client = new GameClient(userId);

client.connect(ServerConfig.serverHost(), ServerConfig.port());
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.cowaine.corock.mission.game;
package com.cowaine.corock.mission.game.client;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;

public class Receiver extends Thread {
class Receiver extends Thread {

private final DataInputStream in;

Expand All @@ -25,9 +25,19 @@ private boolean isReceivable() {

private void receiveMessage() {
try {
System.out.println(in.readUTF());
String response = in.readUTF();
if (isQuitTheGame(response)) {
this.interrupt();
System.exit(0);
}
System.out.print(response);
} catch (IOException e) {
System.err.println(e.getMessage());
}
}

private boolean isQuitTheGame(String response) {
return response.equals("quit");
}

}
Loading