diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssignment2_Client.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssignment2_Client.java new file mode 100644 index 0000000000000000000000000000000000000000..b638d2342feda492e486e74cd8c933e031a8f74f --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssignment2_Client.java @@ -0,0 +1,67 @@ +/* + * 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 MV3500Cohort2018JulySeptember.homework2.Severson; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.Socket; +import javax.swing.JOptionPane; + +/** + * + * @author Peter + */ +public class SeversonAssignment2_Client { + + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + try { + while (true) { + System.out.println("TcpClient creating socket..."); + + int confirmButton = JOptionPane.OK_OPTION; + String message = "Are you sure"; + JOptionPane.showConfirmDialog(null, message); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of the Socket + // object; the server uses a ServerSocket to wait for + // connections. + if (confirmButton == JOptionPane.OK_OPTION) { + + Socket socket = new Socket(LOCALHOST, 2317); // locohost? + + InputStream is = socket.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + + String serverMessage = br.readLine(); + System.out.println("=================================================="); + System.out.println("Now we're talking!"); + System.out.println("The message the server sent was " + serverMessage); + } + } + + } catch (IOException e) { + + System.out.println("Problem with client: "); + System.out.println(e); + + } + + System.out.println("client exit"); + } + + } + diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssingment2_Server.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssingment2_Server.java new file mode 100644 index 0000000000000000000000000000000000000000..36001b59ca8273a365d8d0223b0dbc9195362f8b --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssingment2_Server.java @@ -0,0 +1,58 @@ +/* + * 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 MV3500Cohort2018JulySeptember.homework2.Severson; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * + * @author Peter + */ +public class SeversonAssingment2_Server { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + try { + + System.out.println("TcpServer has started..."); // it helps debugging to put this on console first + ServerSocket serverSocket = new ServerSocket(2317); + + while (true) { + Socket clientConnection = serverSocket.accept(); // block until connected to a client + + OutputStream os = clientConnection.getOutputStream(); + PrintStream ps = new PrintStream(os); + + ps.println("This was written by the server"); // this goes back to client! + + InetAddress localAddress = clientConnection.getLocalAddress(); + InetAddress remoteAddress = clientConnection.getInetAddress(); + + int localPort = clientConnection.getLocalPort(); + int remotePort = clientConnection.getPort(); + + System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( "+ remoteAddress.toString() + ", " + remotePort + " ))"); + + ps.flush(); + clientConnection.close(); + } + } catch (IOException e) { + + System.out.println("problem with networking"); + + } + } + +} +