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
b61ad19c
Commit
b61ad19c
authored
7 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
keep track of connectionCount
parent
b4cfc9e5
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
projects/TcpExample2/src/tcpexample2/TcpExample2.java
+8
-1
8 additions, 1 deletion
projects/TcpExample2/src/tcpexample2/TcpExample2.java
with
8 additions
and
1 deletion
projects/TcpExample2/src/tcpexample2/TcpExample2.java
+
8
−
1
View file @
b61ad19c
...
@@ -31,6 +31,8 @@ public class TcpExample2
...
@@ -31,6 +31,8 @@ public class TcpExample2
// ServerSocket waits for a connection from a client.
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
// needs to be made only once.
int
connectionCount
=
0
;
// state
ServerSocket
serverSocket
=
new
ServerSocket
(
2317
);
ServerSocket
serverSocket
=
new
ServerSocket
(
2317
);
...
@@ -38,7 +40,10 @@ public class TcpExample2
...
@@ -38,7 +40,10 @@ public class TcpExample2
// Stop the program somewhere else.
// Stop the program somewhere else.
while
(
true
)
while
(
true
)
{
{
Socket
clientConnection
=
serverSocket
.
accept
();
Socket
clientConnection
=
serverSocket
.
accept
();
// blocks! then proceeds once a connection is "accept"ed
connectionCount
++;
// got another one!
OutputStream
os
=
clientConnection
.
getOutputStream
();
OutputStream
os
=
clientConnection
.
getOutputStream
();
PrintStream
ps
=
new
PrintStream
(
os
);
PrintStream
ps
=
new
PrintStream
(
os
);
...
@@ -66,6 +71,8 @@ public class TcpExample2
...
@@ -66,6 +71,8 @@ public class TcpExample2
System
.
out
.
println
(
"Socket pair: (( "
+
localAddress
.
toString
()
+
", "
+
localPort
+
" ), ( "
+
System
.
out
.
println
(
"Socket pair: (( "
+
localAddress
.
toString
()
+
", "
+
localPort
+
" ), ( "
+
remoteAddress
.
toString
()
+
", "
+
remotePort
+
" ))"
);
remoteAddress
.
toString
()
+
", "
+
remotePort
+
" ))"
);
System
.
out
.
println
(
"got another connection, #"
+
connectionCount
);
// report progress
// Notice the use of flush() and close(). Without
// Notice the use of flush() and close(). Without
// the close() to Socket object may stay open for
// the close() to Socket object may stay open for
// a while after the client has stopped needing this
// a while after the client has stopped needing this
...
...
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