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

Merge origin/master

Conflicts:
	.gitignore
parents bfd654b5 5b7bd332
No related branches found
No related tags found
No related merge requests found
Showing
with 287 additions and 5 deletions
...@@ -39,4 +39,4 @@ ...@@ -39,4 +39,4 @@
/projects/Assignments/dist/ /projects/Assignments/dist/
/deliverables/build/ /deliverables/build/
/projects/TcpExample3/Server/TcpServer/build/ /projects/TcpExample3/Server/TcpServer/build/
/projects/TcpExample3/Client/TcpClient/build/ /projects/TcpExample3/Client/TcpClient/build/
\ No newline at end of file
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list= annotation.processing.processors.list=
annotation.processing.run.all.processors=true annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=MV3500 Deliverables
application.vendor=don
build.classes.dir=${build.dir}/classes build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned: # This directory is removed when the project is cleaned:
...@@ -26,10 +27,15 @@ dist.archive.excludes= ...@@ -26,10 +27,15 @@ dist.archive.excludes=
dist.dir=dist dist.dir=dist
dist.jar=${dist.dir}/MV3500_Deliverables.jar dist.jar=${dist.dir}/MV3500_Deliverables.jar
dist.javadoc.dir=${dist.dir}/javadoc dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes= excludes=
file.reference.dis-enums-1.3.jar=../lib/dis-enums-1.3.jar
file.reference.open-dis_4.16.jar=../lib/open-dis_4.16.jar
includes=** includes=**
jar.compress=false jar.compress=false
javac.classpath= javac.classpath=\
${file.reference.open-dis_4.16.jar}:\
${file.reference.dis-enums-1.3.jar}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=
javac.deprecation=false javac.deprecation=false
...@@ -54,6 +60,7 @@ javadoc.splitindex=true ...@@ -54,6 +60,7 @@ javadoc.splitindex=true
javadoc.use=true javadoc.use=true
javadoc.version=false javadoc.version=false
javadoc.windowtitle= javadoc.windowtitle=
main.class=MV3500Cohort2018JulySeptember.homework1.CainAssignment1
meta.inf.dir=${src.dir}/META-INF meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=true mkdist.disabled=true
platform.active=default_platform platform.active=default_platform
......
...@@ -11,5 +11,9 @@ ...@@ -11,5 +11,9 @@
<root id="test.src.dir"/> <root id="test.src.dir"/>
</test-roots> </test-roots>
</data> </data>
<spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1">
<word>localhost</word>
<word>multicast</word>
</spellchecker-wordlist>
</configuration> </configuration>
</project> </project>
deliverables/src/MV3500Cohort2018JulySeptember/homework2/CainAssignment2.4Client.png

346 KiB

deliverables/src/MV3500Cohort2018JulySeptember/homework2/CainAssignment2.4Server.png

388 KiB

package MV3500Cohort2018JulySeptember.homework2;
import java.net.Socket;
import java.io.*;
import java.net.*;
/**
* credit to author mcgredo
*/
public class CainTcpClient {
public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1
public static void main(String[] args) {
try {
while (true) {
System.out.println("creating socket");
// * Changed IP from 2317 to 2468.
Socket socket = new Socket(LOCALHOST, 2468); // locohost?
OutputStream os = socket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String inputMessage = "Client: We are under attack! What do we do? ";
System.out.println("Client: we told the server: We are under attack! What do we do? ");
String sendMessage = inputMessage + "\n";
bw.write(sendMessage);
bw.flush();
String input = br.readLine();
System.out.println("Client: copy, server: " + input);
// String serverMessage = br.readLine();
System.out.println("Client: We are on our way!\n" ); // + serverMessage
String update = br.readLine();
// String sendUpdate = update + "\n";
// System.out.println("Answer:" + sendUpdate);
} // end while(true)
} catch (IOException e) {
System.out.println("Problem with client: "); // describe what is happening
System.out.println(e);
}
// program exit: tell somebody about that
System.out.println("client exit");
}
}
package MV3500Cohort2018JulySeptember.homework2;
import java.io.*;
import java.net.*;
/**
*
* telnet localhost 2468
* telnet <ipOfServersLaptop> 2468
* credit to author mcgredo
*/
public class CainTcpServer
{
public static void main(String[] args)
{
try
{
// * Changed IP from 2317 to 2468.
ServerSocket serverSocket = new ServerSocket(2468);
int x = 1;
while(x<=10)
{
System.out.println("server here, starting loop #: " + x);
Socket clientConnection = serverSocket.accept(); // block until connected
InputStream is = clientConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String receivedInput = br.readLine();
System.out.println("Server: the client said: \n" + receivedInput);
String returnInput;
returnInput = "Get to the choppa!"; // shows up
System.out.println("Server: told the client to Get to the choppa!\n");
OutputStream os = clientConnection.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
// bw.write(returnInput);
// System.out.println("Message volley");
PrintStream ps = new PrintStream(os);
ps.println("Get to the choppa!");
ps.println(returnInput);
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 + " ))");
// 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();
x++;
}
}
catch(Exception e)
{
// cosmetic change to print line
System.out.println("You got problems! Deal with it");
}
}
}
\ No newline at end of file
package MV3500Cohort2018JulySeptember.homework2.Furr;
import java.io.*;
import java.net.*;
/**
* Before, we always used telnet to connect to the server.
* Here 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 FurrTcpClient {
public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1
public static void main(String[] args)
{
try
{
while(true)
{
System.out.println("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); // locohost?
// 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("==================================================");
System.out.println("Now we're talking!");
System.out.println("The message the server sent was " + serverMessage);
// socket gets closed, either automatically/silently this code (or possibly by server)
} // end while(true)
}
catch(IOException e)
{
System.out.println("Problem with client: "); // describe what is happening
System.out.println(e);
}
// program exit: tell somebody about that
System.out.println("client exit");
}
}
package MV3500Cohort2018JulySeptember.homework2.Furr;
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 FurrTcpServer
{
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);
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while(true)
{
Socket clientConnection = serverSocket.accept(); // block until connected
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 + " ))");
// 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(); // like it or not, you're outta here!
}
}
catch(IOException e)
{
System.out.println("problem with networking");
}
}
}
\ No newline at end of file
No preview for this file type
build.xml.data.CRC32=c6e94055 build.xml.data.CRC32=db5607e2
build.xml.script.CRC32=14215a97 build.xml.script.CRC32=14215a97
build.xml.stylesheet.CRC32=8064a381@1.80.1.48 build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=c6e94055 nbproject/build-impl.xml.data.CRC32=db5607e2
nbproject/build-impl.xml.script.CRC32=c8e98896 nbproject/build-impl.xml.script.CRC32=c8e98896
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
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