Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: limbero/indaprojekt-2012
base: f02ec27269
...
head fork: limbero/indaprojekt-2012
compare: 741cb54ad1
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 17, 2012
Axel Samuelsson Networking fixes f15f40d
Axel Samuelsson Merge branch 'master' of github.com:limbero/indaprojekt-2012 741cb54
View
BIN  bin/NetworkClient.class
Binary file not shown
View
BIN  bin/NetworkServer.class
Binary file not shown
View
BIN  bin/NetworkServerThread.class
Binary file not shown
View
77 src/NetworkClient.java
@@ -2,18 +2,16 @@
import java.net.*;
import java.util.Scanner;
-/**
- @author Snilledata
-*/
public class NetworkClient {
- private static int connectionPort = 8989;
+ private static int port = 1415;
+ private static String host = "limbero";
+ private static String user = "luddeha";
public static void main(String[] args) throws IOException {
-
- Socket ATMSocket = null;
+ Socket ServerSocket = null;
PrintWriter out = null;
BufferedReader in = null;
- String adress = "130.229.169.77";
+ String adress = "localhost";
/*try {
adress = args[0];
@@ -22,10 +20,10 @@ public static void main(String[] args) throws IOException {
System.exit(1);
}*/
try {
- ATMSocket = new Socket(adress, connectionPort);
- out = new PrintWriter(ATMSocket.getOutputStream(), true);
+ ServerSocket = new Socket(adress, port);
+ out = new PrintWriter(ServerSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader
- (ATMSocket.getInputStream()));
+ (ServerSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Unknown host: " +adress);
System.exit(1);
@@ -34,41 +32,40 @@ public static void main(String[] args) throws IOException {
System.exit(1);
}
- System.out.println("Contacting bank ... ");
- System.out.println(in.readLine());
+ System.out.println("Contacting server ... ");
+ String line = in.readLine();
+ System.out.println(line);
+
+ boolean a = false;
+ boolean b = false;
+ while(!a || !b){
+ if(line != null){
+ if(line.equals("host")){
+ System.out.println("sending "+host);
+ out.println(host);
+ a = true;
+ }
+ if(line.equals("user")){
+ System.out.println("host matched, sending "+user);
+ out.println(user);
+ b = true;
+ }
+ }
+ line = in.readLine();
+ }
+ System.out.println("user matched.");
Scanner scanner = new Scanner(System.in);
System.out.print("> ");
- int menuOption = scanner.nextInt();
- int userInput;
+ String menuOption = scanner.next();
out.println(menuOption);
- while(menuOption < 4) {
- if(menuOption == 1) {
- System.out.println(in.readLine());
- System.out.println(in.readLine());
- System.out.print("> ");
- menuOption = scanner.nextInt();
- out.println(menuOption);
- } else if (menuOption > 3) {
- break;
- }
- else {
- System.out.println(in.readLine());
- userInput = scanner.nextInt();
- out.println(userInput);
- String str;
- do {
- str = in.readLine();
- System.out.println(str);
- } while (! str.startsWith("(1)"));
- System.out.print("> ");
- menuOption = scanner.nextInt();
- out.println(menuOption);
- }
- }
-
+
+ while(!menuOption.equals("exit")){
+
+ }
+
out.close();
in.close();
- ATMSocket.close();
+ ServerSocket.close();
}
}
View
13 src/NetworkServer.java
@@ -1,12 +1,9 @@
import java.net.*;
import java.io.*;
-/**
- @author Viebrapadata
-*/
public class NetworkServer {
- private static int connectionPort = 8989;
+ private static int connectionPort = 1415;
public static void main(String[] args) throws IOException {
@@ -21,10 +18,12 @@ public static void main(String[] args) throws IOException {
System.exit(1);
}
- System.out.println("Bank started listening on port: " + connectionPort);
- while (listening)
+ System.out.println("Server started listening on port: " + connectionPort);
+
+ while (listening) {
new NetworkServerThread(serverSocket.accept()).start();
-
+ }
+
serverSocket.close();
}
}
View
58 src/NetworkServerThread.java
@@ -1,28 +1,25 @@
import java.io.*;
import java.net.*;
-/**
- @author Viebrapadata
-*/
public class NetworkServerThread extends Thread {
private Socket socket = null;
private BufferedReader in;
+ private String owner;
+ private String user;
+
PrintWriter out;
public NetworkServerThread(Socket socket) {
super("NetworkServerThread");
this.socket = socket;
+ owner = "limbero";
+ user = "luddeha";
}
private String readLine() throws IOException {
String str = in.readLine();
- //System.out.println("" + socket + " : " + str);
return str;
}
- private boolean validateUser() {
- return true;
- }
-
public void run(){
try {
@@ -30,37 +27,24 @@ public void run(){
in = new BufferedReader
(new InputStreamReader(socket.getInputStream()));
- String inputLine, outputLine;
-
- int balance = 1000;
- int value;
- validateUser();
- out.println("Welcome to Bank! (1)Balance, (2)Withdrawal, (3)Deposit, (4)Exit");
+ String inputLine;
+
+ boolean matched = false;
+
+ out.println("host");
inputLine = readLine();
- int choise = Integer.parseInt(inputLine);
- while (choise != 4) {
- int deposit = 1;
- switch (choise) {
- case 2:
- deposit = -1;
- case 3:
- out.println("Enter amount: ");
- inputLine= readLine();
- value = Integer.parseInt(inputLine);
- balance += deposit * value;
- case 1:
- out.println("Current balance is " + balance + " dollars");
- out.println("(1)Balance, (2)Withdrawal, (3)Deposit, (4)Exit");
- inputLine=readLine();
- choise = Integer.parseInt(inputLine);
- break;
- case 4:
- break;
- default:
- break;
- }
+ while(!inputLine.equals("exit")){
+ if(inputLine.equals(owner)){
+ System.out.println("right host");
+ out.println("user");
+ inputLine = readLine();
+ matched = true;
+ }
+ if(inputLine.equals(user) && matched){
+ out.println("Welcome "+user);
+ }
}
- out.println("Good Bye");
+
out.close();
in.close();
socket.close();

No commit comments for this range

Something went wrong with that request. Please try again.