Package cs.csc.network.Server

Source Code of cs.csc.network.Server.ClientConnection

package cs.csc.network.Server;

import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

import cs.csc.file.FileRead.FileRead;
public class ClientConnection implements Runnable
{
  public static PrintStream p;
  public static Scanner s;
  public static Socket client;
  public ClientConnection(Socket client)
  {
    ClientConnection.client = client;
  }

  public void run()
  {
    boolean myFlag;
    try
    {
      Thread.sleep(300);
      s = new Scanner(client.getInputStream());
      p = new PrintStream(client.getOutputStream());

      System.out.println("Sending message HELLO");
      p.println("HELLO");
      do
      {
        String ack = s.nextLine();
        System.out.println("Received ACK " + ack);
        if (!ack.equalsIgnoreCase("HITHERE"))
        {
          p.println("Get Lost!");
          System.out.println("What! " + ack);
          myFlag = false;
        }
        else
        {
          System.out.println("New Client Connected.");
          myFlag = true;
        }
      }while(myFlag == false);

      myFlag = false;

      FileRead read = new FileRead();
      String path = s.nextLine();
      String size = s.nextLine();

      read.ReadIt(path, size);

    }
    catch (Exception e)
    {
      System.out.printf("Error in client %s, %e\n", Thread.currentThread(), e);
    }
    System.out.println("Client Disconnected")
  }
}
TOP

Related Classes of cs.csc.network.Server.ClientConnection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.