Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- public class ServerThread extends Thread {
- private Socket socket = null;
- public ServerThread(Socket socket) {
- super("ServerThread");
- this.socket = socket;
- }
- public void run() {
- try {
- PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
- BufferedReader in = new BufferedReader(
- new InputStreamReader(
- socket.getInputStream()));
- Boolean Connected = true;
- String inputLine, outputLine;
- Protocol p = new Protocol();
- MessageHandler m = new MessageHandler();
- //outputLine = p.processInput(null);
- out.println("Connected to the Server.");
- try{
- Thread.currentThread().sleep(10);
- }
- catch(InterruptedException e){}
- out.println("Testing");
- while (Connected = true)
- {
- try{
- Thread.currentThread().sleep(10);
- }
- catch(InterruptedException e){}
- if((inputLine = in.readLine()) != null)
- {
- m.addQueue(inputLine);
- }
- if((outputLine = m.getQueue())!= null)
- {
- System.out.println(outputLine);
- out.println(outputLine);
- out.flush();
- }
- if (outputLine.equals("Bye."))
- break;
- }
- out.close();
- in.close();
- socket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement