Created
September 4, 2017 07:49
-
-
Save FrankHald/a54483ba101d474f25e8ad09bed84e61 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package Talk16T; | |
import java.io.BufferedReader; | |
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.Socket; | |
public class Output extends Thread { | |
private Socket connectionSocket; | |
private DataOutputStream outToClient; | |
private BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); | |
public Output(Socket connectionSocket) { | |
this.connectionSocket = connectionSocket; | |
try { | |
outToClient = new DataOutputStream(connectionSocket.getOutputStream()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void run() { | |
boolean done = false; | |
while (!done) { | |
try { | |
String fromUser = inFromUser.readLine(); | |
if (fromUser.equalsIgnoreCase("/close")) { | |
done = true; | |
} else { | |
outToClient.writeBytes("Server: " + fromUser + "\n"); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
try { | |
connectionSocket.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment