Skip to content
Snippets Groups Projects
Commit 03ac7083 authored by Ayres, Kevin (CAPT)'s avatar Ayres, Kevin (CAPT)
Browse files

Ayres_Client_HW2

parent 37a41138
No related branches found
No related tags found
No related merge requests found
/*
* 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.Ayres;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
/**
*
* @author kjayr
*/
public class Ayres_Client {
public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1
public static void main(String[] args) {
try {
while (true) {
System.out.println("TcpClient creating socket...");
// Socket created to server
Socket socket = new Socket(LOCALHOST, 2317);
// Set up the streams, Java style:
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
// Read/Print messages by server.
String serverMessage = br.readLine();
System.out.println("==================================================");
System.out.println("Server is up and waiting");
System.out.println("The message the server sent was " + serverMessage);
//Set up streams and message to server
OutputStream os = socket.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("**Client operating**...Client-Server Connection Successful");
}
}
catch (IOException e) {
System.out.println("**No Server Connection, Try again later** Problem: Client Out: "); // describe what is happening
System.out.println(e);
}
// program exit: tell somebody about that
System.out.println("client exit");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment