diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework1/DemchkoAssignment1.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework1/DemchkoAssignment1.java new file mode 100644 index 0000000000000000000000000000000000000000..ce03b13e173058abade400180ea73435cefeddc8 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework1/DemchkoAssignment1.java @@ -0,0 +1,53 @@ +package MV3500Cohort2018JulySeptember.homework1; + + +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.ServerSocket; +import java.net.Socket; + +/* + * 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. + */ + +/** + * + * @author ekdem + */ +public class DemchkoAssignment1 { + public static void main(String[] args) + { + try + { + // The ServerSocket waits for a connection from a client. + // It returns a Socket object when the connection occurs. + ServerSocket serverSocket = new ServerSocket(2317); + + // The Socket object represents the connection between + // the server and client, including a full duplex + // connection + Socket clientConnection = serverSocket.accept(); + + // Use Java io classes to write text (as opposed to + // unknown bytes of some sort) to the client + OutputStream os = clientConnection.getOutputStream(); + PrintStream ps = new PrintStream(os); + + ps.println("This client response was written by server Demchko"); // to remote client + System.out.println("This server response was written by server Demchko"); // to server console + ps.println("HelloWorld"); + // "flush()" in important in that it forces a write + // across what is in fact a slow connection + ps.flush(); + + clientConnection.close(); + } + catch(Exception error) + { + System.out.println("Nope, try again because " + error); + } + } + +}