/* * 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 MV3500Cohort2018JanuaryMarch.homework1; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; /** * homework assignment * @author Rico */ public class LandasServer2 { /** * Default constructor to silence javadoc warning * @see <a href="https://stackoverflow.com/questions/4488716/java-default-constructor" target="_blank">StackOverflow: Java default constructor</a> */ public LandasServer2 () { // default initializations occur here } static DataInputStream in; static DataOutputStream out; /** run the program * @param args command-line arguments, string parameters (unused) */ 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); } } }