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
37dfa99f
Commit
37dfa99f
authored
5 years ago
by
brutzman
Browse files
Options
Downloads
Patches
Plain Diff
cleanup comments, warnings
parent
43cdf456
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CourseExamples/src/TcpExamples/TcpExample2ConnectionCounting.java
+6
-10
6 additions, 10 deletions
...amples/src/TcpExamples/TcpExample2ConnectionCounting.java
with
6 additions
and
10 deletions
CourseExamples/src/TcpExamples/TcpExample2ConnectionCounting.java
+
6
−
10
View file @
37dfa99f
...
...
@@ -18,11 +18,10 @@ import java.net.*;
* <code>telnet ipOfServersLaptop 2317</code>
*
* And have that machine display the socket pairs received.
* @author mcgredo
* @author mcgredo
, brutzman
*/
public
class
TcpExample2ConnectionCounting
{
public
static
void
main
(
String
[]
args
)
{
try
...
...
@@ -31,8 +30,7 @@ public class TcpExample2ConnectionCounting
System
.
out
.
println
(
" enter (nc localhost 2317) or (telnet localhost 2317)..."
);
// 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.
int
connectionCount
=
0
;
// state variable
...
...
@@ -55,9 +53,8 @@ public class TcpExample2ConnectionCounting
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.)
// 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
();
...
...
@@ -69,8 +66,7 @@ public class TcpExample2ConnectionCounting
// 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?
// Why is first IP/port the same, while the second set has different ports?
System
.
out
.
println
(
"Socket pair: (( "
+
localAddress
.
toString
()
+
", "
+
localPort
+
" ), ( "
+
remoteAddress
.
toString
()
+
", "
+
remotePort
+
" ))"
);
...
...
@@ -85,7 +81,7 @@ public class TcpExample2ConnectionCounting
clientConnection
.
close
();
}
}
catch
(
Exception
e
)
catch
(
IO
Exception
e
)
{
System
.
out
.
println
(
"problem with networking: "
+
e
);
}
...
...
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