Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Author: Austin Bowmar
- * Date: 10/10/2018
- * Server Source File
- *
- */
- import java.io.*;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.Scanner;
- public class Server
- {
- //initialize socket and input stream
- private Socket socket = null;
- private ServerSocket server = null;
- private DataInputStream in = null;
- // constructor with port
- public Server()
- {
- try
- {
- server = new ServerSocket(50001);
- System.out.println("Server started");
- System.out.println("Waiting for a client ...");
- socket = server.accept();
- System.out.println("Client accepted");
- // takes input from the client socket
- in = new DataInputStream(
- new BufferedInputStream(socket.getInputStream()));
- String line = "";
- //String[] cliInput = line.split("\\s+");
- File file = new File("Users.txt");
- Scanner sc = new Scanner(file);
- String var = sc.nextLine();
- String[] split = var.split("\\s+");
- String User = split[0];
- String Pass = split[1];
- // reads message from client until "Done" is sent
- while (!line.equals("DONE"))
- {
- try
- {
- line = in.readUTF();
- String[] cliInput = line.split("\\s+");
- switch(cliInput[0]) {
- case "USER":
- boolean valid = false;
- while(sc.hasNextLine() && valid != true) {
- if(split[0].equals( cliInput[1])){
- System.out.println("maybe it works.");
- valid = true;
- }
- else{
- }
- }
- break;
- case "PASS":
- if(split[1].equals(cliInput[1])){
- System.out.println("You may enter.");
- }
- else{
- System.out.println("Nah.");
- }
- break;
- case "LIST":
- System.out.println("FUCK3");
- break;
- case "KILL":
- System.out.println("FUCK4");
- break;
- case "RETR":
- System.out.println("FUCK5");
- break;
- }
- System.out.println(line);
- }
- catch(IOException i)
- {
- System.out.println(i);
- }
- }
- System.out.println("Closing connection");
- // close connection
- socket.close();
- in.close();
- }
- catch(IOException i)
- {
- System.out.println(i);
- }
- }
- public static void main(String args[])
- {
- Server server = new Server();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement