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
082b3d37
Commit
082b3d37
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
show localhost IP number to facilitate connections over local area network (LAN, WAN)
parent
bb78d6db
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/TcpExample2ConnectionCounting.java
+11
-2
11 additions, 2 deletions
examples/src/TcpExamples/TcpExample2ConnectionCounting.java
with
11 additions
and
2 deletions
examples/src/TcpExamples/TcpExample2ConnectionCounting.java
+
11
−
2
View file @
082b3d37
...
@@ -33,7 +33,16 @@ public class TcpExample2ConnectionCounting
...
@@ -33,7 +33,16 @@ public class TcpExample2ConnectionCounting
{
{
System
.
out
.
println
(
"TcpExample2ConnectionCounting has started and is waiting for a connection."
);
System
.
out
.
println
(
"TcpExample2ConnectionCounting has started and is waiting for a connection."
);
System
.
out
.
println
(
" help: https://savage.nps.edu/Savage/developers.html#telnet"
);
System
.
out
.
println
(
" help: https://savage.nps.edu/Savage/developers.html#telnet"
);
System
.
out
.
println
(
" enter (nc localhost 2317) or (telnet localhost 2317)..."
);
// Where are we? In other words, what is our host number? Advertise it
// https://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java
String
localHostAddress
=
Inet4Address
.
getLocalHost
().
toString
();
System
.
out
.
println
(
"Local host address is "
+
localHostAddress
);
if
(
localHostAddress
.
contains
(
"/"
))
localHostAddress
=
localHostAddress
.
substring
(
localHostAddress
.
indexOf
(
"/"
)+
1
);
// show localhost IP number to facilitate connections over local area network (LAN, WAN)
System
.
out
.
println
(
" enter (nc localhost 2317) or (telnet localhost 2317) for local operation"
);
System
.
out
.
println
(
" enter (nc "
+
localHostAddress
+
" 2317) or "
+
"(telnet "
+
localHostAddress
+
" 2317)..."
);
// ServerSocket waits for a connection from a client.
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket needs to be made only once.
// Notice that it is outside the loop; ServerSocket needs to be made only once.
...
@@ -42,7 +51,7 @@ public class TcpExample2ConnectionCounting
...
@@ -42,7 +51,7 @@ public class TcpExample2ConnectionCounting
ServerSocket
serverSocket
=
new
ServerSocket
(
2317
);
// server decides here what port to listen on.
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.
// of interest: often client doesn't care what port it uses locally when connecting to that server port.
// Loop, infinitely, waiting for client connections.
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
// Stop the program somewhere else.
while
(
true
)
while
(
true
)
...
...
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