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
90ca7928
Commit
90ca7928
authored
4 years ago
by
Terry D. Norbraten
Browse files
Options
Downloads
Patches
Plain Diff
format
parent
295a7be8
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/TcpExample4Client.java
+42
-46
42 additions, 46 deletions
examples/src/TcpExamples/TcpExample4Client.java
with
42 additions
and
46 deletions
examples/src/TcpExamples/TcpExample4Client.java
+
42
−
46
View file @
90ca7928
...
...
@@ -5,66 +5,62 @@ import java.net.*;
//import java.time.LocalTime; // conversion?
/**
* This client program establishes a socket connection
* to the dispatch server, then checks how long it takes to read the single
* line it expects.
*
* This client program establishes a socket connection to the dispatch server,
* then checks how long it takes to read the single line it expects.
*
* @author Don McGregor
* @author Don Brutzman
* @author MV3500 class
*/
public
class
TcpExample4Client
{
public
class
TcpExample4Client
{
static
int
MAX_LOOP_COUNT
=
4
;
public
static
void
main
(
String
[]
args
)
{
try
{
System
.
out
.
println
(
"TcpExample4Client start, loop "
+
MAX_LOOP_COUNT
+
" times"
);
System
.
out
.
println
(
"=================================================="
);
for
(
int
loopCount
=
1
;
loopCount
<=
MAX_LOOP_COUNT
;
loopCount
++)
// loop then exit
{
System
.
out
.
println
(
"TcpExample4Client creating socket #"
+
loopCount
+
"..."
);
// We request an IP to connect to ("localhost") and
// port number at that IP (2317). This establishes
// a connection to that IP in the form of the Socket
// object; the server uses a ServerSocket to wait for
// connections.This particualar example is interacting
// with what it expects is a server that writes a single text
// line after 10 sec.
long
startTime
=
System
.
currentTimeMillis
();
public
static
void
main
(
String
[]
args
)
{
try
{
System
.
out
.
println
(
"TcpExample4Client start, loop "
+
MAX_LOOP_COUNT
+
" times"
);
System
.
out
.
println
(
"=================================================="
);
for
(
int
loopCount
=
1
;
loopCount
<=
MAX_LOOP_COUNT
;
loopCount
++)
// loop then exit
{
System
.
out
.
println
(
"TcpExample4Client creating socket #"
+
loopCount
+
"..."
);
// We request an IP to connect to ("localhost") and
// port number at that IP (2317). This establishes
// a connection to that IP in the form of the Socket
// object; the server uses a ServerSocket to wait for
// connections.This particualar example is interacting
// with what it expects is a server that writes a single text
// line after 10 sec.
long
startTime
=
System
.
currentTimeMillis
();
// open a socket for each loop
Socket
socket
=
new
Socket
(
"localhost"
,
2317
);
Socket
socket
=
new
Socket
(
"localhost"
,
2317
);
// Setup. Read the single line written by the server.
// We'd do things a bit differently if many lines to be read
// from the server, instead of one only.
InputStream
is
=
socket
.
getInputStream
();
InputStreamReader
isr
=
new
InputStreamReader
(
is
);
BufferedReader
br
=
new
BufferedReader
(
isr
);
String
serverMessage
=
br
.
readLine
();
// blocks
long
readTime
=
System
.
currentTimeMillis
();
long
timeLength
=
readTime
-
startTime
;
// Setup. Read the single line written by the server.
// We'd do things a bit differently if many lines to be read
// from the server, instead of one only.
InputStream
is
=
socket
.
getInputStream
();
InputStreamReader
isr
=
new
InputStreamReader
(
is
);
BufferedReader
br
=
new
BufferedReader
(
isr
);
System
.
out
.
println
(
"TcpExample4Client: message received from server='"
+
serverMessage
+
"'"
);
System
.
out
.
println
(
"TcpExample4Client: time msec required for read="
+
timeLength
);
System
.
out
.
println
(
"=================================================="
);
// To push this further, launch multiple copies of TcpExample4Client simultaneously
}
System
.
out
.
println
(
"TcpExample4Client complete"
);
String
serverMessage
=
br
.
readLine
();
// blocks
long
readTime
=
System
.
currentTimeMillis
();
long
timeLength
=
readTime
-
startTime
;
System
.
out
.
println
(
"TcpExample4Client: message received from server='"
+
serverMessage
+
"'"
);
System
.
out
.
println
(
"TcpExample4Client: time msec required for read="
+
timeLength
);
System
.
out
.
println
(
"=================================================="
);
// To push this further, launch multiple copies of TcpExample4Client simultaneously
}
System
.
out
.
println
(
"TcpExample4Client complete"
);
// main method now exits
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Problem with TcpExample4Client networking:networking:"
);
// describe what is happening
System
.
out
.
println
(
"Error: "
+
e
);
// Provide more helpful information to user if exception occurs due to running twice at one time
if
(
e
instanceof
java
.
net
.
BindException
)
if
(
e
instanceof
java
.
net
.
BindException
)
{
System
.
out
.
println
(
"*** Be sure to stop any other running instances of programs using this port!"
);
}
}
}
}
\ No newline at end of file
}
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