Skip to content
Snippets Groups Projects
Commit 9df6bd6c authored by courtneythomerson's avatar courtneythomerson
Browse files

Thomerson Homework 1

parents 8a479d69 d554287a
No related branches found
No related tags found
No related merge requests found
Showing
with 1459 additions and 1479 deletions
This diff is collapsed.
build.xml.data.CRC32=c32b23cd
build.xml.script.CRC32=a4dd9aad
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=c32b23cd
nbproject/build-impl.xml.script.CRC32=f3635930
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
build.xml.data.CRC32=ac015f70
build.xml.script.CRC32=a4dd9aad
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=ac015f70
nbproject/build-impl.xml.script.CRC32=f3635930
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
compile.on.save=true
user.properties.file=/Users/courtneythomerson/Library/Application Support/NetBeans/8.2/build.properties
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/Users/mcgredo/projects/gitlab/NetworkedGraphicsMV3500/projects/TcpExample2/src/tcpexample2/TcpExample2.java</file>
</group>
</open-files>
</project-private>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>TcpExample2</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>TcpExample2</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
<spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1">
<word>localhost</word>
</spellchecker-wordlist>
</configuration>
</project>
package tcpexample2;
import java.io.*;
......@@ -16,7 +15,7 @@ import java.net.*;
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* telnet <ipOfServersLaptop> 2317
* <code>telnet ipOfServersLaptop 2317</code>
*
* And have him display the socket pairs he got.
* @author mcgredo
......@@ -34,7 +33,8 @@ public class TcpExample2
int connectionCount = 0; // state
ServerSocket serverSocket = new ServerSocket(2317);
ServerSocket serverSocket = new ServerSocket(2317); // server decides here what port to listen on.
// of interest: often client doesn't care what port it uses locally when connecting to that server port.
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
......@@ -47,29 +47,30 @@ public class TcpExample2
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This response was written by server TcpExample2"); // to remote client
System.out.println("This response was written by server TcpExample2"); // to server console
ps.println("This client response was written by server TcpExample2"); // to remote client
System.out.println("This server response was written by server TcpExample2"); // to server console
ps.println("You were connection #" + connectionCount + ", by my count");
// 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 localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort(); // remember the prior question, why are 2 ports different?
// 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, 54876 )) note IPv6
// 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 + " ))");
remoteAddress.toString() + ", " + remotePort + " ))");
System.out.println("got another connection, #" + connectionCount); // report progress
......@@ -85,7 +86,5 @@ public class TcpExample2
{
System.out.println("problem with networking: " + e);
}
}
}
// TODO not needed? can ignore for now
package tcpexample2;
......
compile.on.save=true
user.properties.file=C:\\Users\\Justin Snell\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
</project-private>
compile.on.save=true
user.properties.file=C:\\Users\\Justin Snell\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
</project-private>
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