diff --git a/projects/Assignments/homework1/LandasAssignment01_ConsoleOutput.pdf b/projects/Assignments/homework1/LandasAssignment01_ConsoleOutput.pdf new file mode 100644 index 0000000000000000000000000000000000000000..8b43977fec2e46f3248f2e4cdb3a219d8958a7b0 Binary files /dev/null and b/projects/Assignments/homework1/LandasAssignment01_ConsoleOutput.pdf differ diff --git a/projects/Assignments/homework1/LandasClient1.java b/projects/Assignments/homework1/LandasClient1.java new file mode 100644 index 0000000000000000000000000000000000000000..35304866a467058b7c024bcd377df7c95f92e059 --- /dev/null +++ b/projects/Assignments/homework1/LandasClient1.java @@ -0,0 +1,51 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mv3500_assignments; + +import java.io.*; +import java.net.*; + +/** + * + * @author Rico + */ +public class LandasClient1 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + try + { + System.out.println("Creating Socket"); + Socket cs = new Socket("localhost", 2317); + + while (true) { + + PrintStream cp = new PrintStream(cs.getOutputStream()); + System.out.print("\nClient: \n"); + System.out.print("Please enter entity identifier and position: "); + InputStreamReader cir = new InputStreamReader(System.in); + BufferedReader cbr = new BufferedReader(cir); + String temp1 = cbr.readLine(); + cp.println(temp1); + BufferedReader cbr1 = new BufferedReader(new InputStreamReader(cs.getInputStream())); + String temp2 = cbr1.readLine(); + System.out.print(temp2); + + } + } + catch(Exception e) + { + System.out.println(e); + System.out.println(" Problem with client"); + + } + + } + +} diff --git a/projects/Assignments/homework1/LandasClient2.java b/projects/Assignments/homework1/LandasClient2.java new file mode 100644 index 0000000000000000000000000000000000000000..79949d8bc53146d1b3d6295ff41c64f6b57fa960 --- /dev/null +++ b/projects/Assignments/homework1/LandasClient2.java @@ -0,0 +1,66 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mv3500_assignments; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.Socket; +import java.util.Scanner; +/** + * + * @author Rico + */ +public class LandasClient2 { + + public static DataInputStream in; + public static DataOutputStream out; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + //declare a scanner so we can write a message + Scanner keyboard = new Scanner(System.in); + + // localhost ip + String ip = "127.0.0.1"; + int port = 2317; + Socket socket; + + try { + + //connect + socket = new Socket(ip, port); + + //initialize streams + //DataInputStream in = new DataInputStream(socket.getInputStream()); + //DataOutputStream out = new DataOutputStream(socket.getOutputStream()); + in = new DataInputStream(socket.getInputStream()); + out = new DataOutputStream(socket.getOutputStream()); + + + while (true){ + System.out.print("\nMessage to server: "); + //Write a message + String message = keyboard.nextLine(); + //Send it to the server which will print it and send a confirmation + out.writeUTF(message); + + // recieve the incoming messages and print + String message2 = in.readUTF(); + System.out.println(message2); + } + + } + catch(IOException e) { + System.out.println(e); + System.out.println("\nProblem with client"); + } + } + +} diff --git a/projects/Assignments/homework1/LandasServer1.java b/projects/Assignments/homework1/LandasServer1.java new file mode 100644 index 0000000000000000000000000000000000000000..923b913a57abb0bac95d28274582d0aaf7630700 --- /dev/null +++ b/projects/Assignments/homework1/LandasServer1.java @@ -0,0 +1,55 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mv3500_assignments; + +import java.io.*; +import java.net.*; + +/** + * + * @author Rico + */ +public class LandasServer1 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + try + { + ServerSocket ss = new ServerSocket(2317); + + while(true) { + + Socket cs = ss.accept(); + BufferedReader cbr = new BufferedReader(new InputStreamReader(cs.getInputStream())); + String temp = cbr.readLine(); + //System.out.println("Client:" + temp); + //JOptionPane.showMessageDialog(null,"Salam"); + PrintStream spr = new PrintStream(cs.getOutputStream()); + String temp1 = "Server: I got your message: " + temp; + spr.println(temp1); + //server(); + + } + + + } + catch(Exception e) { + System.out.println("problem with networking"); + } + + + + + + + + + } + +} diff --git a/projects/Assignments/homework1/LandasServer2.java b/projects/Assignments/homework1/LandasServer2.java new file mode 100644 index 0000000000000000000000000000000000000000..6082f4b091d3c707ce9053c90a599725710710e1 --- /dev/null +++ b/projects/Assignments/homework1/LandasServer2.java @@ -0,0 +1,68 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mv3500_assignments; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; + + +/** + * + * @author Rico + */ +public class LandasServer2 { + + public static DataInputStream in; + public static DataOutputStream out; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + int port = 2317; + ServerSocket server; + Socket clientSocket; + + try { + + //start listening on port + server = new ServerSocket(port); + + System.out.println("Listening on port: " + port); + + //Accept client + clientSocket = server.accept(); + + System.out.println("Client Connected!"); + + //initialize streams so we can send message + in = new DataInputStream(clientSocket.getInputStream()); + out = new DataOutputStream(clientSocket.getOutputStream()); + + String message; + + while (true) { + + // as soon as a message is being received, print it out! + message = in.readUTF(); + System.out.println("Server received: " + message); + // send a message confirmation to the client + String temp1 = "Server: I received your message of " + "'" + message + "'"; + out.writeUTF(temp1); + + } + + } + catch(IOException e) { + System.out.println("problem with networking: " + e); + } + } + +}