Skip to content
Snippets Groups Projects
Commit 66832560 authored by Justin Snell's avatar Justin Snell
Browse files

ConardSnellFinalProj - old file removal

parent c9667b04
No related branches found
No related tags found
No related merge requests found
Showing
with 21 additions and 214 deletions
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class ConardSnellPositionReceiver {
/**
* @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);
}
}
}
\ No newline at end of file
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 ConardSnellPositionSender {
/**
* @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");
}
}
}
\ No newline at end of file
## Final Course Projects 2018March
Create a dedicated subdirectory for each individual or team project.
Example: `SmithJones`
See the course syllabus for details on how to document your project.
//package tcpclient;
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 ConardTcpClient {
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("What is your location? " + serverMessage);
}
catch(Exception e)
{
System.out.println(e);
System.out.println("Problem with client");
}
}
}
//package tcpserver;
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 ConardTcpServer
{
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);
// System.out.println("socketCreated");
// 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("My location is 1,2,5");
// 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();
}
}
catch(Exception e)
{
System.out.println("problem with networking");
}
}
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ import java.net.*;
*
* @author mcgredo
*/
public class ConardTcpClient {
public class SnellConardTcpClient {
public static void main(String[] args)
......
......@@ -21,7 +21,7 @@ import java.net.*;
* And have him display the socket pairs he got.
* @author mcgredo
*/
public class ConardTcpServer
public class SnellConardTcpServer
{
public static void main(String[] args)
......
......@@ -125,6 +125,7 @@ is divided into following sections:
</condition>
<condition property="have.sources">
<or>
<available file="${src.FinalProjects.dir}"/>
<available file="${src.homework3.dir}"/>
<available file="${src.homework1.dir}"/>
<available file="${src.homework2.dir}"/>
......@@ -230,6 +231,7 @@ is divided into following sections:
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
<fail unless="src.FinalProjects.dir">Must set src.FinalProjects.dir</fail>
<fail unless="src.homework3.dir">Must set src.homework3.dir</fail>
<fail unless="src.homework1.dir">Must set src.homework1.dir</fail>
<fail unless="src.homework2.dir">Must set src.homework2.dir</fail>
......@@ -253,7 +255,7 @@ is divided into following sections:
</target>
<target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors">
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}" name="srcdir"/>
<attribute default="${src.FinalProjects.dir}:${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<attribute default="${javac.processorpath}" name="processorpath"/>
......@@ -294,7 +296,7 @@ is divided into following sections:
</target>
<target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal">
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}" name="srcdir"/>
<attribute default="${src.FinalProjects.dir}:${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<attribute default="${javac.processorpath}" name="processorpath"/>
......@@ -327,7 +329,7 @@ is divided into following sections:
</target>
<target depends="-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac">
<macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}" name="srcdir"/>
<attribute default="${src.FinalProjects.dir}:${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<sequential>
......@@ -915,11 +917,12 @@ is divided into following sections:
<include name="*"/>
</dirset>
</pathconvert>
<j2seproject3:depend srcdir="${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}:${build.generated.subdirs}"/>
<j2seproject3:depend srcdir="${src.FinalProjects.dir}:${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}:${build.generated.subdirs}"/>
</target>
<target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
<j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
<copy todir="${build.classes.dir}">
<fileset dir="${src.FinalProjects.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
<fileset dir="${src.homework3.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
<fileset dir="${src.homework1.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
<fileset dir="${src.homework2.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
......@@ -943,7 +946,7 @@ is divided into following sections:
<target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
<j2seproject3:force-recompile/>
<j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}"/>
<j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.FinalProjects.dir}:${src.homework3.dir}:${src.homework1.dir}:${src.homework2.dir}"/>
</target>
<target name="-post-compile-single">
<!-- Empty placeholder for easier customization. -->
......@@ -1209,6 +1212,9 @@ is divided into following sections:
<classpath>
<path path="${javac.classpath}"/>
</classpath>
<fileset dir="${src.FinalProjects.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
<filename name="**/*.java"/>
</fileset>
<fileset dir="${src.homework3.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
<filename name="**/*.java"/>
</fileset>
......@@ -1225,6 +1231,9 @@ is divided into following sections:
<arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/>
</javadoc>
<copy todir="${dist.javadoc.dir}">
<fileset dir="${src.FinalProjects.dir}" excludes="${excludes}" includes="${includes}">
<filename name="**/doc-files/**"/>
</fileset>
<fileset dir="${src.homework3.dir}" excludes="${excludes}" includes="${includes}">
<filename name="**/doc-files/**"/>
</fileset>
......
build.xml.data.CRC32=b21d1ee7
build.xml.data.CRC32=80187eb2
build.xml.script.CRC32=71581cc3
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.
# 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=b21d1ee7
nbproject/build-impl.xml.script.CRC32=3800b3a5
nbproject/build-impl.xml.data.CRC32=80187eb2
nbproject/build-impl.xml.script.CRC32=53c6ba36
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
......@@ -76,6 +76,7 @@ run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.FinalProjects.dir=FinalProjects
src.homework1.dir=homework1
src.homework2.dir=homework2
src.homework3.dir=homework3
......@@ -5,6 +5,7 @@
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>Assignments: MV3500 Homework</name>
<source-roots>
<root id="src.FinalProjects.dir"/>
<root id="src.homework3.dir"/>
<root id="src.homework1.dir"/>
<root id="src.homework2.dir"/>
......
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