Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
08a37cca
Commit
08a37cca
authored
5 years ago
by
brutzman
Browse files
Options
Downloads
Patches
Plain Diff
show both HostName and HostAddress
parent
b64f8bc0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/src/TcpExamples/TcpExample3Server.java
+12
-5
12 additions, 5 deletions
examples/src/TcpExamples/TcpExample3Server.java
with
12 additions
and
5 deletions
examples/src/TcpExamples/TcpExample3Server.java
+
12
−
5
View file @
08a37cca
...
@@ -20,6 +20,7 @@ import java.net.*;
...
@@ -20,6 +20,7 @@ import java.net.*;
* and have the instructor display the socket pairs received.
* and have the instructor display the socket pairs received.
*
*
* @author mcgredo
* @author mcgredo
* @author brutzman
*/
*/
public
class
TcpExample3Server
{
public
class
TcpExample3Server
{
...
@@ -52,18 +53,24 @@ public class TcpExample3Server {
...
@@ -52,18 +53,24 @@ public class TcpExample3Server {
// Print some information locally about the Socket connection.
// Print some information locally about the Socket connection.
// This includes the port and IP numbers on both sides (the socket pair).
// This includes the port and IP numbers on both sides (the socket pair).
localAddress
=
clientConnection
.
getLocalAddress
();
localAddress
=
clientConnection
.
getLocalAddress
();
remoteAddress
=
clientConnection
.
getInetAddress
();
remoteAddress
=
clientConnection
.
getInetAddress
();
localPort
=
clientConnection
.
getLocalPort
();
localPort
=
clientConnection
.
getLocalPort
();
remotePort
=
clientConnection
.
getPort
();
remotePort
=
clientConnection
.
getPort
();
// My socket pair connection looks like this, to localhost:
// 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 ))
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
// 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?
// Why is the first IP/port the same, while the second set has different ports?
System
.
out
.
println
(
"TcpExample3Server socket pair: (( "
+
localAddress
.
toString
()
+
", "
+
localPort
+
" ), ( "
System
.
out
.
println
(
"TcpExample3Server socket pair showing host name, address, port:"
);
+
remoteAddress
.
toString
()
+
", "
+
remotePort
+
" ))"
);
System
.
out
.
println
(
" (( "
+
localAddress
.
getHostName
()
+
"="
+
localAddress
.
getHostAddress
()
+
", "
+
localPort
+
" ), ( "
+
remoteAddress
.
getHostName
()
+
"="
+
remoteAddress
.
getHostAddress
()
+
", "
+
remotePort
+
" ))"
);
if
(
localAddress
.
getHostName
().
equals
(
localAddress
.
getHostAddress
())
||
remoteAddress
.
getHostName
().
equals
(
remoteAddress
.
getHostAddress
()))
System
.
out
.
println
(
" note HostName matches address if host has no DNS name"
);
// Notice the use of flush() and try w/ resources. Without
// Notice the use of flush() and try w/ resources. Without
// the try w/ resources the Socket object may stay open for
// the try w/ resources the Socket object may stay open for
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment