Created
September 4, 2017 07:48
-
-
Save FrankHald/2229acc746bb2af281dd85e31a1cd53d 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.IOException; | |
import java.io.InputStreamReader; | |
import java.net.Socket; | |
public class Input extends Thread { | |
private BufferedReader inFromClient; | |
private Socket connectionSocket; | |
public Input(Socket connectionSocket) { | |
this.connectionSocket = connectionSocket; | |
try { | |
inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void run() { | |
boolean done = false; | |
while (!done) { | |
try { | |
String text = inFromClient.readLine(); | |
if (text.equalsIgnoreCase("/close")) { | |
done = true; | |
} | |
else { | |
System.out.println("Client: " + inFromClient.readLine()); | |
} | |
} 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