Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • stefan.goericke.gy/NetworkedGraphicsMV3500
  • william.mahan/NetworkedGraphicsMV3500
  • alexander.white/NetworkedGraphicsMV3500
  • kyle.britt/NetworkedGraphicsMV3500
  • christopher.garibay/NetworkedGraphicsMV3500
  • christopher.cannon/NetworkedGraphicsMV3500
  • galoeffe/NetworkedGraphicsMV3500
  • dlcain1/NetworkedGraphicsMV3500
  • jmfurr/NetworkedGraphicsMV3500
  • jrjackso1/NetworkedGraphicsMV3500
  • kjmaroon1/NetworkedGraphicsMV3500
  • cdtacket/NetworkedGraphicsMV3500
12 results
Show changes
Showing
with 1284 additions and 1095 deletions
## Student assignments: homework submission directories
* [Homework 1 README](homework1/README.md)
* [Homework 2 README](homework2/README.md)
* [Homework 3 README](homework3/README.md)
* [Homework 4 README](homework4/README.md)
Please see the [README.md](../../../README.md) in the parent
[assignments](../../../../assignments) directory for detailed instructions.
\ No newline at end of file
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.
*/
// no package required or desired, use Netbeans menu item "Run File
import java.io.*;
import java.net.*;
/**
*
* @author cs2017
*/
public class AngelClient {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
boolean operate = true;
while (operate)
{
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();
if ("Exit".equals(serverMessage)){
System.out.println("The server has asked to shut the client down.");
operate = false;
}
else {
int spd = Integer.parseInt(br.readLine());
int x = Integer.parseInt(br.readLine());
int y = Integer.parseInt(br.readLine());
int z = Integer.parseInt(br.readLine());
String lastCommand = br.readLine();
AngelTank tank = new AngelTank(serverMessage, spd, new int[]{x, y, z});
System.out.println(serverMessage+" is traveling at "+spd+" with position ("+x+", "+y+", "+z+").");
if ("Exit".equals(lastCommand)){
System.out.println("The server has asked to shut the client down.");
operate = false;
}
}
}
catch(IOException 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.
*/
// no package required or desired, use Netbeans menu item "Run File
import java.io.*;
import java.net.*;
/**
* homework assignment
* @author cs2017
*/
public class AngelClient
{
/**
* 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 AngelClient ()
{
// default initializations occur here
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public static void main(String[] args)
{
boolean operate = true;
while (operate)
{
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();
if ("Exit".equals(serverMessage)){
System.out.println("The server has asked to shut the client down.");
operate = false;
}
else {
int spd = Integer.parseInt(br.readLine());
int x = Integer.parseInt(br.readLine());
int y = Integer.parseInt(br.readLine());
int z = Integer.parseInt(br.readLine());
String lastCommand = br.readLine();
AngelTank tank = new AngelTank(serverMessage, spd, new int[]{x, y, z});
System.out.println(serverMessage+" is traveling at "+spd+" with position ("+x+", "+y+", "+z+").");
if ("Exit".equals(lastCommand)){
System.out.println("The server has asked to shut the client down.");
operate = false;
}
}
}
catch(IOException e)
{
System.out.println(e);
System.out.println("Problem with client");
}
}
}
}
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.
*/
// no package required or desired, use Netbeans menu item "Run File"
import java.io.*;
import java.net.*;
/**
*
* @author cs2017
*/
public class AngelServer {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
boolean goforit = true;
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(goforit)
{
Socket clientConnection = serverSocket.accept();
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
// 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 + " ))");
// 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.println("Abrams 1");
ps.println(60);
ps.println(152);
ps.println(25);
ps.println(30);
ps.println("Exit");
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.
*/
// no package required or desired, use Netbeans menu item "Run File"
import java.io.*;
import java.net.*;
/**
* homework assignment
* @author cs2017
*/
public class AngelServer
{
/**
* 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 AngelServer ()
{
// default initializations occur here
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
boolean goforit = true;
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(goforit)
{
Socket clientConnection = serverSocket.accept();
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
// 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 + " ))");
// 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.println("Abrams 1");
ps.println(60);
ps.println(152);
ps.println(25);
ps.println(30);
ps.println("Exit");
ps.flush();
clientConnection.close();
}
}
catch(Exception e)
{
System.out.println("problem with networking");
}
}
}
\ No newline at end of file
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.
*/
// no package required or desired, Netbeans will automatically compile
/**
*
* @author cs2017
*/
public class AngelTank {
private String type;
private int speed;
private int[] position;
AngelTank(String type, int i, int[] pos) {
this.type = type;
this.speed = i;
this.position = pos;
}
/**
* @return the type
*/
public String getType() {
return type;
}
/**
* @return the speed
*/
public int getSpeed() {
return speed;
}
/**
* @return the position
*/
public int[] getPosition() {
return position;
}
}
/*
* 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.
*/
// no package required or desired, Netbeans will automatically compile
/**
* homework assignment
* @author cs2017
*/
public class AngelTank {
private String type;
private int speed;
private int[] position;
AngelTank(String type, int i, int[] pos) {
this.type = type;
this.speed = i;
this.position = pos;
}
/**
* get current type
* @return the type
*/
public String getType() {
return type;
}
/**
* get current speed
* @return the speed
*/
public int getSpeed() {
return speed;
}
/**
* get current position
* @return the position
*/
public int[] getPosition() {
return position;
}
}
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
{
/**
* 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 BlankenbekerMyTcpClient ()
{
// default initializations occur here
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
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 <ipOfServersLaptop> 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
{
/**
* 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 BlankenbekerMyTcpServer ()
{
// default initializations occur here
}
/** 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.*;
/**
* homework assignment
* @author Brian
*/
public class HanleyTcpClient
{
/**
* 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 HanleyTcpClient ()
{
// default initializations occur here
}
/** 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 <ipOfServersLaptop> 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.*;
/**
* 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 Brian
*/
public class HanleyTcpServer
{
/**
* 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 HanleyTcpServer ()
{
// default initializations occur here
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
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.*;
import java.net.*;
/**
*
* @author Rico
*/
public class LandasClient1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
System.out.println("Creating Socket");
Socket cs = new Socket("localhost", 2317);
while (true) {
PrintStream cp = new PrintStream(cs.getOutputStream());
System.out.print("\nClient: \n");
System.out.print("Please enter entity identifier and position: ");
InputStreamReader cir = new InputStreamReader(System.in);
BufferedReader cbr = new BufferedReader(cir);
String temp1 = cbr.readLine();
cp.println(temp1);
BufferedReader cbr1 = new BufferedReader(new InputStreamReader(cs.getInputStream()));
String temp2 = cbr1.readLine();
System.out.print(temp2);
}
}
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 MV3500Cohort2018JanuaryMarch.homework1;
import java.io.*;
import java.net.*;
/**
* homework assignment
* @author Rico
*/
public class LandasClient1
{
/**
* 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 LandasClient1 ()
{
// default initializations occur here
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public static void main(String[] args) {
try
{
System.out.println("Creating Socket");
Socket cs = new Socket("localhost", 2317);
while (true) {
PrintStream cp = new PrintStream(cs.getOutputStream());
System.out.print("\nClient: \n");
System.out.print("Please enter entity identifier and position: ");
InputStreamReader cir = new InputStreamReader(System.in);
BufferedReader cbr = new BufferedReader(cir);
String temp1 = cbr.readLine();
cp.println(temp1);
BufferedReader cbr1 = new BufferedReader(new InputStreamReader(cs.getInputStream()));
String temp2 = cbr1.readLine();
System.out.print(temp2);
}
}
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 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 the 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;
/**
* homework assignment
* @author Rico
*/
public class LandasClient2
{
/**
* 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 LandasClient2 ()
{
// default initializations
}
static DataInputStream in;
static DataOutputStream out;
/**
* Program invocation, execution starts here
* @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.*;
import java.net.*;
/**
*
* @author Rico
*/
public class LandasServer1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
ServerSocket ss = new ServerSocket(2317);
while(true) {
Socket cs = ss.accept();
BufferedReader cbr = new BufferedReader(new InputStreamReader(cs.getInputStream()));
String temp = cbr.readLine();
//System.out.println("Client:" + temp);
//JOptionPane.showMessageDialog(null,"Salam");
PrintStream spr = new PrintStream(cs.getOutputStream());
String temp1 = "Server: I got your message: " + temp;
spr.println(temp1);
//server();
}
}
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.*;
import java.net.*;
/**
* homework assignment
* @author Rico
*/
public class LandasServer1
{
/**
* 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 LandasServer1 ()
{
// default initializations occur here
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public static void main(String[] args) {
try
{
ServerSocket ss = new ServerSocket(2317);
while(true) {
Socket cs = ss.accept();
BufferedReader cbr = new BufferedReader(new InputStreamReader(cs.getInputStream()));
String temp = cbr.readLine();
//System.out.println("Client:" + temp);
//JOptionPane.showMessageDialog(null,"Salam");
PrintStream spr = new PrintStream(cs.getOutputStream());
String temp1 = "Server: I got your message: " + temp;
spr.println(temp1);
//server();
}
}
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.ServerSocket;
import java.net.Socket;
/**
*
* @author Rico
*/
public class LandasServer2 {
public static DataInputStream in;
public static DataOutputStream out;
/**
* @param args the 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;
/**
* 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);
}
}
}
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
{
/**
* 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 MaroonTcpClient ()
{
// default initializations
}
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 <ipOfServersLaptop> 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
{
/**
* 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 MaroonTcpServer ()
{
// default initializations
}
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 Assignment01;
import java.io.*;
import java.net.*;
/**
*
* @author Jeremiah Sasala
*/
public class SasalaClient {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
while(true){
try
{
System.out.println("-------------------------------------------------------------------");
// from the server, instead of one only.
Socket socket = new Socket("127.0.0.1", 2317);
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage01 = br.readLine();
String serverMessage02 = br.readLine();
String serverMessage03 = br.readLine();
String serverMessage04 = br.readLine();
String serverMessage05 = br.readLine();
System.out.println("The message the server sent was . . . " + serverMessage01);
System.out.println("The message the server sent was . . . " + serverMessage02);
System.out.println("The message the server sent was . . . " + serverMessage03);
System.out.println("The message the server sent was . . . " + serverMessage04);
System.out.println("The message the server sent was . . . " + serverMessage05);
}
catch(Exception e)
{
System.out.println("Problem with client");
System.out.println(e);
}
}
}
}
//package Assignment01;
import java.io.*;
import java.net.*;
/**
* homework assignment
* @author Jeremiah Sasala
*/
public class SasalaClient
{
/**
* 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 SasalaClient ()
{
// default initializations
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
while(true){
try
{
System.out.println("-------------------------------------------------------------------");
// from the server, instead of one only.
Socket socket = new Socket("127.0.0.1", 2317);
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage01 = br.readLine();
String serverMessage02 = br.readLine();
String serverMessage03 = br.readLine();
String serverMessage04 = br.readLine();
String serverMessage05 = br.readLine();
System.out.println("The message the server sent was . . . " + serverMessage01);
System.out.println("The message the server sent was . . . " + serverMessage02);
System.out.println("The message the server sent was . . . " + serverMessage03);
System.out.println("The message the server sent was . . . " + serverMessage04);
System.out.println("The message the server sent was . . . " + serverMessage05);
}
catch(Exception e)
{
System.out.println("Problem with client");
System.out.println(e);
}
}
}
}
package MV3500Cohort2018JanuaryMarch.homework1;
//package Assignment01;
import java.io.*;
import java.net.*;
/**
*
* @author Jeremiah Sasala
*/
public class SasalaServer {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
ServerSocket serverSocket = new ServerSocket(2317);
while(true)
{
Socket clientConnection = serverSocket.accept();
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
String entityName = "Ranger";
double xPos = Math.round(Math.random()*10);
double yPos = Math.round(Math.random()*10);
double zPos = Math.round(Math.random()*10);
ps.println("Entity position information");
ps.println("Name: " + entityName);
ps.println("X coordinate: " + xPos);
ps.println("Y coordinate: " + yPos);
ps.println("Z coordinate: " + zPos);
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(Exception e)
{
System.out.println("problem with networking: " + e);
}
}
}
//package Assignment01;
import java.io.*;
import java.net.*;
/**
* homework assignment
* @author Jeremiah Sasala
*/
public class SasalaServer
{
/**
* 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 SasalaServer ()
{
// default initializations
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public static void main(String[] args) {
try
{
ServerSocket serverSocket = new ServerSocket(2317);
while(true)
{
Socket clientConnection = serverSocket.accept();
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
String entityName = "Ranger";
double xPos = Math.round(Math.random()*10);
double yPos = Math.round(Math.random()*10);
double zPos = Math.round(Math.random()*10);
ps.println("Entity position information");
ps.println("Name: " + entityName);
ps.println("X coordinate: " + xPos);
ps.println("Y coordinate: " + yPos);
ps.println("Z coordinate: " + zPos);
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(Exception e)
{
System.out.println("problem with networking: " + e);
}
}
}
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 the 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;
/**
* homework assignment
* @author AJSNELL
*/
public class SnellPositionClient
{
/**
* 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 SnellPositionClient ()
{
// default initializations
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
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 the 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;
/** Program description goes here */
public class SnellPositionServer
{
/**
* 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 SnellPositionServer ()
{
// default initializations
}
/**
* Program invocation, execution starts here
* @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
......@@ -4,7 +4,6 @@ package MV3500Cohort2018JanuaryMarch.homework1;
import java.net.Socket;
import java.io.*;
import java.net.*;
/**
* Before, we always used telnet to connect to the server. We are now writing
......@@ -16,11 +15,22 @@ import java.net.*;
*
* @author mcgredo
*/
public class TackettTcpClient {
public class TackettTcpClient
{
/**
* 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 TackettTcpClient ()
{
// default initializations
}
/** 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 {
......
......@@ -20,14 +20,23 @@ import java.net.*;
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* telnet <ipOfServersLaptop> 2317
* telnet [ipAddressOfServerLaptop] 2317
*
* And have him display the socket pairs he got.
* @author mcgredo
*/
public class TackettTcpServer
{
/**
* 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 TackettTcpServer ()
{
// default initializations
}
/** run the program
* @param args command-line arguments, string parameters (unused) */
public static void main(String[] args)
{
try
......