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
b4cfc9e5
Commit
b4cfc9e5
authored
7 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
improved diagnostics, comments
parent
955ed8bc
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/TcpExample3/Client/TcpClient/src/tcpclient/TcpClient.java
+14
-7
14 additions, 7 deletions
...TcpExample3/Client/TcpClient/src/tcpclient/TcpClient.java
with
14 additions
and
7 deletions
projects/TcpExample3/Client/TcpClient/src/tcpclient/TcpClient.java
+
14
−
7
View file @
b4cfc9e5
...
...
@@ -5,8 +5,8 @@ import java.io.*;
import
java.net.*
;
/**
* Before, we always used telnet to connect to the server.
We
* are now writing our own program to do the connection.
* Before, we always used telnet to connect to the server.
*
Here we
are now writing our own program to do the connection.
*
* As you will see, when we run this after we start the server
* we will see the same string telnet printed, sent by the server.
...
...
@@ -17,11 +17,14 @@ import java.net.*;
*/
public
class
TcpClient
{
public
final
static
String
LOCALHOST
=
"0:0:0:0:0:0:0:1"
;
// String constant, i.e. 127.0.0.1
public
static
void
main
(
String
[]
args
)
{
try
{
while
(
true
)
{
System
.
out
.
println
(
"creating socket"
);
// We request an IP to connect to ("localhost") and
...
...
@@ -29,7 +32,7 @@ public class TcpClient {
// a connection to that IP in the form of the Socket
// object; the server uses a ServerSocket to wait for
// connections.
Socket
socket
=
new
Socket
(
"localhost"
,
2317
);
Socket
socket
=
new
Socket
(
LOCALHOST
,
2317
);
// locohost?
// Read the single line written by the server. We'd
// do things a bit differently if many lines to be read
...
...
@@ -39,15 +42,19 @@ public class TcpClient {
BufferedReader
br
=
new
BufferedReader
(
isr
);
String
serverMessage
=
br
.
readLine
();
System
.
out
.
println
(
"=================================================="
);
System
.
out
.
println
(
"Now we're talking!"
);
System
.
out
.
println
(
"The message the server sent was "
+
serverMessage
);
// socket gets closed, either automatically/silently this code (or possibly by server)
}
// end while(true)
}
catch
(
Exception
e
)
catch
(
IO
Exception
e
)
{
System
.
out
.
println
(
"Problem with client: "
);
// describe what is happening
System
.
out
.
println
(
e
);
System
.
out
.
println
(
"Problem with client"
);
}
// program exit: tell somebody about that
System
.
out
.
println
(
"client exit"
);
}
}
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