Skip to content
Snippets Groups Projects
Commit 49dc7402 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

javadoc

parent fcb8228e
No related branches found
No related tags found
No related merge requests found
Showing
with 890 additions and 868 deletions
package MV3500Cohort2018JanuaryMarch.homework1;
/*
* 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 mv3500code;
import java.io.*;
import java.net.*;
/**
* Before, we always used telnet to connect to the server. We
* are now writing our own program to do the connection.
*
* As you will see, when we run this after we start the server
* we will see the same string telnet printed, sent by the server.
* The output at the server will show different socket pairs for
* each time we ran it.
*
* @author mcgredo
*/
public class BlankenbekerMyTcpClient {
public static void main(String[] args)
{
try
{
while(true){
System.out.println("creating socket");
// 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.
Socket socket = new Socket("localhost", 2317);
// Read the single line written by the server. We'd
// do things a bit differently if many lines to be read
// from the server, instead of one only.
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage = br.readLine();
System.out.println("The message the server sent was " + serverMessage);
OutputStream os = socket.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This response was written by myTcpClient"); // to remote client
// "flush()" in important in that it forces a write
// across what is in fact a slow connection
ps.flush();
}
}
catch(IOException e)
{
System.out.println(e);
System.out.println("Problem with client :" + e);
}
System.out.println("client exit");
}
}
/*
* 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 mv3500code;
import java.io.*;
import java.net.*;
/**
* Before, we always used telnet to connect to the server. We
* are now writing our own program to do the connection.
*
* As you will see, when we run this after we start the server
* we will see the same string telnet printed, sent by the server.
* The output at the server will show different socket pairs for
* each time we ran it.
*
* @author mcgredo
*/
public class BlankenbekerMyTcpClient {
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
{
while(true){
System.out.println("creating socket");
// 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.
Socket socket = new Socket("localhost", 2317);
// Read the single line written by the server. We'd
// do things a bit differently if many lines to be read
// from the server, instead of one only.
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage = br.readLine();
System.out.println("The message the server sent was " + serverMessage);
OutputStream os = socket.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This response was written by myTcpClient"); // to remote client
// "flush()" in important in that it forces a write
// across what is in fact a slow connection
ps.flush();
}
}
catch(IOException e)
{
System.out.println(e);
System.out.println("Problem with client :" + e);
}
System.out.println("client exit");
}
}
package MV3500Cohort2018JanuaryMarch.homework1;
//package mv3500code;
import java.io.*;
import java.net.*;
/**
* Very slightly more complex than example1. A complete copy of
* example 2. The only thing this does
* differently is introduce a loop into the response, so you don't
* have to restart the program after one response. Also, it prints
* out the socket pair the server sees. Run the program via telnet
* several times and compare the socket pairs.
*
* telnet localhost 2317
*
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* telnet [ipAddressOfServerLaptop] 2317
*
* And have him display the socket pairs he got.
* @author mcgredo
*/
public class BlankenbekerMyTcpServer
{
public static void main(String[] args)
{
try
{
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
int connectionCount = 0;
ServerSocket serverSocket = new ServerSocket(2317);
Socket clientConnection = serverSocket.accept();
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while(true)
{
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
connectionCount++;
ps.println("This was written by the server");
InputStream is = clientConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage = br.readLine();
System.out.println("The message the client sent was " + serverMessage);
// Print some information locally about the Socket
// connection. This includes the port and IP numbers
// on both sides (the socket pair.)
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
// My socket pair connection looks like this, to localhost:
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 ))
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
//
// Why is the first IP/port the same, while the second set has
// different ports?
System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " +
remoteAddress.toString() + ", " + remotePort + " ))");
System.out.println("Connection count is: " + connectionCount);
// Notice the use of flush() and close(). Without
// the close() to Socket object may stay open for
// a while after the client has stopped needing this
// connection. Close() explicitly ends the connection.
ps.flush();
clientConnection.close();
}
}
catch(Exception e)
{
System.out.println("problem with networking");
}
}
}
//package mv3500code;
import java.io.*;
import java.net.*;
/**
* Very slightly more complex than example1. A complete copy of
* example 2. The only thing this does
* differently is introduce a loop into the response, so you don't
* have to restart the program after one response. Also, it prints
* out the socket pair the server sees. Run the program via telnet
* several times and compare the socket pairs.
*
* telnet localhost 2317
*
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* telnet [ipAddressOfServerLaptop] 2317
*
* And have him display the socket pairs he got.
* @author mcgredo
*/
public class BlankenbekerMyTcpServer
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
{
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
int connectionCount = 0;
ServerSocket serverSocket = new ServerSocket(2317);
Socket clientConnection = serverSocket.accept();
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while(true)
{
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
connectionCount++;
ps.println("This was written by the server");
InputStream is = clientConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage = br.readLine();
System.out.println("The message the client sent was " + serverMessage);
// Print some information locally about the Socket
// connection. This includes the port and IP numbers
// on both sides (the socket pair.)
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
// My socket pair connection looks like this, to localhost:
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 ))
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
//
// Why is the first IP/port the same, while the second set has
// different ports?
System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " +
remoteAddress.toString() + ", " + remotePort + " ))");
System.out.println("Connection count is: " + connectionCount);
// Notice the use of flush() and close(). Without
// the close() to Socket object may stay open for
// a while after the client has stopped needing this
// connection. Close() explicitly ends the connection.
ps.flush();
clientConnection.close();
}
}
catch(Exception e)
{
System.out.println("problem with networking");
}
}
}
package MV3500Cohort2018JanuaryMarch.homework1;
/*
* 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 Homework1;
import java.io.*;
import java.net.*;
/**
*
* @author Brian
*/
public class HanleyTcpClient {
public static void main(String[] args)
{
try
{
System.out.println("creating socket");
// 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.
Socket socket = new Socket("localhost", 2317);
// Read the single line written by the server. We'd
// do things a bit differently if many lines to be read
// from the server, instead of one only.
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage = br.readLine();
System.out.println("1 The message the server sent was " + serverMessage);
// Outgoing Messages
OutputStream os = socket.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("bbb report: X, Y, X " + System.currentTimeMillis());
serverMessage = br.readLine();
System.out.println("2 The message the server sent was " + serverMessage);
//os = socket.getOutputStream();
// ps = new PrintStream(os);
ps.println("Final message from client " + System.currentTimeMillis());
serverMessage = br.readLine();
System.out.println("3 The message the server sent was " + serverMessage);
}
catch(Exception e)
{
System.out.println(e);
System.out.println("Problem with client");
}
}
}
/*
* 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 Homework1;
import java.io.*;
import java.net.*;
/**
*
* @author Brian
*/
public class HanleyTcpClient
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
{
System.out.println("creating socket");
// 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.
Socket socket = new Socket("localhost", 2317);
// Read the single line written by the server. We'd
// do things a bit differently if many lines to be read
// from the server, instead of one only.
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage = br.readLine();
System.out.println("1 The message the server sent was " + serverMessage);
// Outgoing Messages
OutputStream os = socket.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("bbb report: X, Y, X " + System.currentTimeMillis());
serverMessage = br.readLine();
System.out.println("2 The message the server sent was " + serverMessage);
//os = socket.getOutputStream();
// ps = new PrintStream(os);
ps.println("Final message from client " + System.currentTimeMillis());
serverMessage = br.readLine();
System.out.println("3 The message the server sent was " + serverMessage);
}
catch(Exception e)
{
System.out.println(e);
System.out.println("Problem with client");
}
}
}
package MV3500Cohort2018JanuaryMarch.homework1;
//package Homework1;
import java.io.*;
import java.net.*;
/**
*
* @author Brian
*/
public class HanleyTcpServer {
/**
* Very slightly more complex than example1. A complete copy of
* example 2. The only thing this does
* differently is introduce a loop into the response, so you don't
* have to restart the program after one response. Also, it prints
* out the socket pair the server sees. Run the program via telnet
* several times and compare the socket pairs.
*
* telnet localhost 2317
*
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* telnet [ipAddressOfServerLaptop] 2317
*
* And have him display the socket pairs he got.
* @author mcgredo
*/
public static void main(String[] args)
{
try
{
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
ServerSocket serverSocket = new ServerSocket(2317);
Socket clientConnection = serverSocket.accept();
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while(true)
{
//Socket clientConnection = serverSocket.accept();
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This was written by the server");
// Print some information locally about the Socket
// connection. This includes the port and IP numbers
// on both sides (the socket pair.)
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
// My socket pair connection looks like this, to localhost:
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 ))
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
//
// Why is the first IP/port the same, while the second set has
// different ports?
System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " +
remoteAddress.toString() + ", " + remotePort + " ))");
//Exchange of Data
InputStream is = clientConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String clientMessage = br.readLine();
if (clientMessage.startsWith("loc")){
System.out.println("Location Report \n"+ clientMessage);
}
else System.out.println("Incoming Message \n" + clientMessage);
ps.println("Message received");
// Notice the use of flush() and close(). Without
// the close() to Socket object may stay open for
// a while after the client has stopped needing this
// connection. Close() explicitly ends the connection.
ps.flush();
clientConnection.close();
}
}
catch(Exception e)
{
System.out.println("problem with networking");
}
}
}
//package Homework1;
import java.io.*;
import java.net.*;
/**
*
* @author Brian
*/
public class HanleyTcpServer {
/**
* Very slightly more complex than example1. A complete copy of
* example 2. The only thing this does
* differently is introduce a loop into the response, so you don't
* have to restart the program after one response. Also, it prints
* out the socket pair the server sees. Run the program via telnet
* several times and compare the socket pairs.
*
* telnet localhost 2317
*
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* telnet [ipAddressOfServerLaptop] 2317
*
* And have him display the socket pairs he got.
* @param args command-line arguments, string parameters (unused)
* @author mcgredo
*/
public static void main(String[] args)
{
try
{
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
ServerSocket serverSocket = new ServerSocket(2317);
Socket clientConnection = serverSocket.accept();
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while(true)
{
//Socket clientConnection = serverSocket.accept();
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This was written by the server");
// Print some information locally about the Socket
// connection. This includes the port and IP numbers
// on both sides (the socket pair.)
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
// My socket pair connection looks like this, to localhost:
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 ))
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
//
// Why is the first IP/port the same, while the second set has
// different ports?
System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " +
remoteAddress.toString() + ", " + remotePort + " ))");
//Exchange of Data
InputStream is = clientConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String clientMessage = br.readLine();
if (clientMessage.startsWith("loc")){
System.out.println("Location Report \n"+ clientMessage);
}
else System.out.println("Incoming Message \n" + clientMessage);
ps.println("Message received");
// Notice the use of flush() and close(). Without
// the close() to Socket object may stay open for
// a while after the client has stopped needing this
// connection. Close() explicitly ends the connection.
ps.flush();
clientConnection.close();
}
}
catch(Exception e)
{
System.out.println("problem with networking");
}
}
}
/*
* 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.Socket;
import java.util.Scanner;
/**
*
* @author Rico
*/
public class LandasClient2 {
public static DataInputStream in;
public static DataOutputStream out;
/**
* @param args 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");
}
}
}
/*
* 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.Socket;
import java.util.Scanner;
/**
*
* @author Rico
*/
public class LandasClient2 {
static DataInputStream in;
static DataOutputStream out;
/**
* @param args 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");
}
}
}
/*
* 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;
/**
*
* @author Rico
*/
public class LandasServer2 {
public static DataInputStream in;
public static DataOutputStream out;
/**
* @param args 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);
}
}
}
/*
* 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;
/**
*
* @author Rico
*/
public class LandasServer2 {
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);
}
}
}
package MV3500Cohort2018JanuaryMarch.homework1;
//package tcpclient;
import java.io.*;
import java.net.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;
/**
* Before, we always used telnet to connect to the server. We
* are now writing our own program to do the connection.
*
* As you will see, when we run this after we start the server
* we will see the same string telnet printed, sent by the server.
* The output at the server will show different socket pairs for
* each time we ran it.
*
* @author mcgredo
*/
public class MaroonTcpClient {
public static DataInputStream input;
public static DataOutputStream output;
public static void main(String[] args)
{
Scanner userInput = new Scanner(System.in);
try
{
System.out.println("creating socket");
Socket socket = new Socket("localhost", 2317);
input = new DataInputStream(socket.getInputStream());
output = new DataOutputStream(socket.getOutputStream());
System.out.println("Type position or ID: \n ");
String request;
request = userInput.nextLine();
output.writeUTF(request);
String reply;
reply = input.readUTF();
System.out.println(reply);
}
catch(Exception e)
{
System.out.println(e);
System.out.println("Problem with client");
}
}
}
//package tcpclient;
import java.io.*;
import java.net.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;
/**
* Before, we always used telnet to connect to the server. We
* are now writing our own program to do the connection.
*
* As you will see, when we run this after we start the server
* we will see the same string telnet printed, sent by the server.
* The output at the server will show different socket pairs for
* each time we ran it.
*
* @author mcgredo
*/
public class MaroonTcpClient {
static DataInputStream input;
static DataOutputStream output;
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
Scanner userInput = new Scanner(System.in);
try
{
System.out.println("creating socket");
Socket socket = new Socket("localhost", 2317);
input = new DataInputStream(socket.getInputStream());
output = new DataOutputStream(socket.getOutputStream());
System.out.println("Type position or ID: \n ");
String request;
request = userInput.nextLine();
output.writeUTF(request);
String reply;
reply = input.readUTF();
System.out.println(reply);
}
catch(Exception e)
{
System.out.println(e);
System.out.println("Problem with client");
}
}
}
package MV3500Cohort2018JanuaryMarch.homework1;
//package tcpserver;
import java.io.*;
import java.net.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
/**
* Very slightly more complex than example1. A complete copy of
* example 2. The only thing this does
* differently is introduce a loop into the response, so you don't
* have to restart the program after one response. Also, it prints
* out the socket pair the server sees. Run the program via telnet
* several times and compare the socket pairs.
*
* telnet localhost 2317
*
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* telnet [ipAddressOfServerLaptop] 2317
*
* And have him display the socket pairs he got.
* @author mcgredo
*/
public class MaroonTcpServer
{
public static DataInputStream input;
public static DataOutputStream output;
public static void main(String[] args)
{
MaroonUnit testUnit1 = new MaroonUnit ();
try
{
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
ServerSocket serverSocket = new ServerSocket(2317);
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while(true)
{
Socket clientConnection = serverSocket.accept();
//OutputStream os = clientConnection.getOutputStream();
input = new DataInputStream(clientConnection.getInputStream());
output = new DataOutputStream(clientConnection.getOutputStream());
String request = input.readUTF();
request = request.trim(); // get rid of outer whitespace
if ("position".equalsIgnoreCase(request)){
output.writeUTF(Arrays.toString(testUnit1.getPosition()));
}
else if ("ID".equalsIgnoreCase(request)){
output.writeUTF(""+ testUnit1.getID());
}else
output.writeUTF("I don't understand, try www.google.com");
// Notice the use of flush() and close(). Without
// the close() to Socket object may stay open for
// a while after the client has stopped needing this
// connection. Close() explicitly ends the connection.
clientConnection.close();
}
}
catch(Exception e)
{
System.out.println("problem with networking");
}
}
//package tcpserver;
import java.io.*;
import java.net.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
/**
* Very slightly more complex than example1. A complete copy of
* example 2. The only thing this does
* differently is introduce a loop into the response, so you don't
* have to restart the program after one response. Also, it prints
* out the socket pair the server sees. Run the program via telnet
* several times and compare the socket pairs.
*
* telnet localhost 2317
*
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* telnet [ipAddressOfServerLaptop] 2317
*
* And have him display the socket pairs he got.
* @author mcgredo
*/
public class MaroonTcpServer
{
static DataInputStream input;
static DataOutputStream output;
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
MaroonUnit testUnit1 = new MaroonUnit ();
try
{
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
ServerSocket serverSocket = new ServerSocket(2317);
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while(true)
{
Socket clientConnection = serverSocket.accept();
//OutputStream os = clientConnection.getOutputStream();
input = new DataInputStream(clientConnection.getInputStream());
output = new DataOutputStream(clientConnection.getOutputStream());
String request = input.readUTF();
request = request.trim(); // get rid of outer whitespace
if ("position".equalsIgnoreCase(request)){
output.writeUTF(Arrays.toString(testUnit1.getPosition()));
}
else if ("ID".equalsIgnoreCase(request)){
output.writeUTF(""+ testUnit1.getID());
}else
output.writeUTF("I don't understand, try www.google.com");
// Notice the use of flush() and close(). Without
// the close() to Socket object may stay open for
// a while after the client has stopped needing this
// connection. Close() explicitly ends the connection.
clientConnection.close();
}
}
catch(Exception e)
{
System.out.println("problem with networking");
}
}
}
\ No newline at end of file
package MV3500Cohort2018JanuaryMarch.homework1;
//package PositionClient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
/**
*
* @author AJSNELL
*/
public class SnellPositionClient {
/**
* @param args command-line arguments
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
String hostName = args[0];
try (Socket clientSocket = new Socket(hostName, 8005);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))) {
String userInput;
out.println("unit id: 1\nunit pos: 11S MS 4859 9849");
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("from client: " + in.readLine());
}
} catch (UnknownHostException e) {
System.err.println("Don't know about host " + hostName);
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to " + hostName);
System.exit(1);
}
}
//package PositionClient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
/**
*
* @author AJSNELL
*/
public class SnellPositionClient {
/**
* @param args command-line arguments, must include hostname
*/
public static void main(String[] args)
{
String hostName = args[0]; // poor practice, ought to throw meaningful exception message
try (Socket clientSocket = new Socket(hostName, 8005);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))) {
String userInput;
out.println("unit id: 1\nunit pos: 11S MS 4859 9849");
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("from client: " + in.readLine());
}
} catch (UnknownHostException e) {
System.err.println("Don't know about host " + hostName);
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to " + hostName);
System.exit(1);
}
}
}
\ No newline at end of file
package MV3500Cohort2018JanuaryMarch.homework1;
//package positionserver;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.PrintWriter;
public class SnellPositionServer {
/**
* @param args command-line arguments
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
try (ServerSocket serverSocket = new ServerSocket(8005);
Socket clientSocket = serverSocket.accept();
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));) {
System.out.println("Client connected on port 8005");
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println("Received message: " + inputLine + " from " + clientSocket.toString());
out.println(inputLine);
}
} catch (IOException e) {
System.out.println("Exception when trying to listen on port 8005");
}
}
//package positionserver;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.PrintWriter;
public class SnellPositionServer {
/**
* @param args command-line arguments
*/
public static void main(String[] args)
{
try (ServerSocket serverSocket = new ServerSocket(8005);
Socket clientSocket = serverSocket.accept();
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));) {
System.out.println("Client connected on port 8005");
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println("Received message: " + inputLine + " from " + clientSocket.toString());
out.println(inputLine);
}
} catch (IOException e) {
System.out.println("Exception when trying to listen on port 8005");
}
}
}
\ No newline at end of file
......@@ -16,11 +16,14 @@ import java.net.*;
*
* @author mcgredo
*/
public class TackettTcpClient {
public class TackettTcpClient
{
/** socket parameter of interest */
public final static String LOCALHOST = "localhost";
//String can also be IPV4 127.0.0.1 or IPV6 0:0:0:0:0:0:0:1
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args) {
try {
......
......@@ -27,7 +27,8 @@ import java.net.*;
*/
public class TackettTcpServer
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
......
......@@ -13,8 +13,10 @@ import java.net.*;
* @version 20180212
*
*/
public class YamashitaDeMouraTcpClient {
public class YamashitaDeMouraTcpClient
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
......
......@@ -17,7 +17,8 @@ import java.net.*;
*/
public class YamashitaDeMouraTcpServer
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
......
......@@ -14,7 +14,8 @@ import java.net.*;
*/
public class AyresAssignment1
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
......
......@@ -12,8 +12,10 @@ import java.net.*;
* ask for the ip address of the server
* <code>telnet ipOfServersLaptop 2318</code>
*/
public class CainAssignment1 {
public class CainAssignment1
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args) {
try {
System.out.println("Hello invoker, this server process is now running"); // reporting for duty
......
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);
}
}
}
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
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
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);
}
}
}
package MV3500Cohort2018JulySeptember.homework1;
import java.io.*;
import java.net.*;
public class DemchkoAssignment2
{
public static void main(String[] args) throws IOException
{
try
{
ServerSocket[] serverSocket = new ServerSocket[9];
int connectionCount = 0;
int j = 0;
for(int i=2317; j<9; i++){
serverSocket[j] = new ServerSocket(i);
System.out.println("server in port " +i +" in array position " +j); //changed
j++;
}
j=0;
while(true)
{
try (
Socket clientConnection = serverSocket[j].accept();
)
{
connectionCount++;
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This client response was written by server DemchkoAssignment2"); //changed
System.out.println("This server response was written by server DemchkoAssignment2"); //changed
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
System.out.println("The socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " +
remoteAddress.toString() + ", " + remotePort + " ))");
System.out.println("next connection, #" + connectionCount); // report progress
j++;
ps.flush();
}
}
}
catch(Exception error)
{
System.out.println("nope, not today: " + error);
}
}
package MV3500Cohort2018JulySeptember.homework1;
import java.io.*;
import java.net.*;
public class DemchkoAssignment2
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
{
ServerSocket[] serverSocket = new ServerSocket[9];
int connectionCount = 0;
int j = 0;
for(int i=2317; j<9; i++){
serverSocket[j] = new ServerSocket(i);
System.out.println("server in port " +i +" in array position " +j); //changed
j++;
}
j=0;
while(true)
{
try (
Socket clientConnection = serverSocket[j].accept();
)
{
connectionCount++;
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This client response was written by server DemchkoAssignment2"); //changed
System.out.println("This server response was written by server DemchkoAssignment2"); //changed
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
System.out.println("The socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " +
remoteAddress.toString() + ", " + remotePort + " ))");
System.out.println("next connection, #" + connectionCount); // report progress
j++;
ps.flush();
}
}
}
catch(Exception error)
{
System.out.println("nope, not today: " + error);
}
}
}
\ No newline at end of file
package MV3500Cohort2018JulySeptember.homework1;
import java.io.*;
import java.net.*;
/**
* The simplest possible TCP network program. It listens for
* a connection, from telnet (telnet localhost 2317) or a program
* you write, which we will do later. Right now the TcpExample simply
* writes a string in response to a connection.
*
* Testing the running server program from telnet looks like this:
*
* it154916:projects mcgredo$ telnet localhost 2317
* Trying ::1...
* Connected to localhost.
* Escape character is '^]'.
* This was written by the server
* Connection closed by foreign host.
*
* Notice that "This was written by the server" matches
* what is written by the code below, over the output stream.
*
* After this first connection the program below drops out
* the bottom of the program, and does not repeat itself.
* The program exits.
*
* @author mcgredo
*/
public class FriscoAssignment1
{
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 FriscoAssignment1"); // to remote client
System.out.println("This server response was written by server FriscoAssignment1"); // to server console
ps.println("No time to say 'Hello, Goodbye' I'm late, I'm late, I'm late");
// "flush()" in important in that it forces a write
// across what is in fact a slow connection
ps.flush();
clientConnection.close();
}
catch(Exception e)
{
System.out.println("I am sorry Neo but you took the 'Red pill': " + e);
}
}
}
package MV3500Cohort2018JulySeptember.homework1;
import java.io.*;
import java.net.*;
/**
* The simplest possible TCP network program. It listens for
* a connection, from telnet (telnet localhost 2317) or a program
* you write, which we will do later. Right now the TcpExample simply
* writes a string in response to a connection.
*
* Testing the running server program from telnet looks like this:
*
* it154916:projects mcgredo$ telnet localhost 2317
* Trying ::1...
* Connected to localhost.
* Escape character is '^]'.
* This was written by the server
* Connection closed by foreign host.
*
* Notice that "This was written by the server" matches
* what is written by the code below, over the output stream.
*
* After this first connection the program below drops out
* the bottom of the program, and does not repeat itself.
* The program exits.
*
* @author mcgredo
*/
public class FriscoAssignment1
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
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 FriscoAssignment1"); // to remote client
System.out.println("This server response was written by server FriscoAssignment1"); // to server console
ps.println("No time to say 'Hello, Goodbye' I'm late, I'm late, I'm late");
// "flush()" in important in that it forces a write
// across what is in fact a slow connection
ps.flush();
clientConnection.close();
}
catch(Exception e)
{
System.out.println("I am sorry Neo but you took the 'Red pill': " + e);
}
}
}
......@@ -29,7 +29,8 @@ import java.net.*;
*/
public class FurrAssignment1
{
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
......
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