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
059c7b7d
Commit
059c7b7d
authored
3 years ago
by
Fisher, Alexander (Alex) (Capt)
Browse files
Options
Downloads
Patches
Plain Diff
Homework 2 - Final
parent
ad7be47b
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
assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherClient.java
+93
-92
93 additions, 92 deletions
...ohort2021JulySeptember/homework2/Fisher/FisherClient.java
with
93 additions
and
92 deletions
assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherClient.java
+
93
−
92
View file @
059c7b7d
package
MV3500Cohort2021JulySeptember.homework2.Fisher
;
//import static MV3500Cohort2020JulySeptember.homework2.White.WhiteClient.LOCALHOST;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
import
java.net.Socket
;
/**
* Before, we always used telnet (netcat) 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. The output at the server will
* show different socket pairs for each time the loop iterates.
*
* @author adfis
*/
public
class
FisherClient
{
// IPv6 String constant for localhost address, similarly IPv4 127.0.0.1
public
final
static
String
LOCALHOST
=
"172.20.145.10"
;
//"0:0:0:0:0:0:0:1";
// if we sub localhost with someone's IP this
//should work the same
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public
static
void
main
(
String
[]
args
)
{
// Local variables/fields
Socket
socket
;
InputStream
is
;
InputStreamReader
isr
;
BufferedReader
br
;
OutputStream
os
;
PrintStream
ps
;
String
serverMessage
;
int
clientLoopCount
=
1
;
try
{
System
.
out
.
println
(
"FisherClient creating socket..."
);
while
(
clientLoopCount
<=
10
)
{
// 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 a Socket
// object; the server uses a ServerSocket to wait for
// connections.
socket
=
new
Socket
(
LOCALHOST
,
2317
);
os
=
socket
.
getOutputStream
();
ps
=
new
PrintStream
(
os
);
// Now hook everything up (i.e. set up the streams), Java style:
is
=
socket
.
getInputStream
();
isr
=
new
InputStreamReader
(
is
);
br
=
new
BufferedReader
(
isr
);
// Read a single line written by the server. We'd
// do things a bit differently if there were many lines to be read
// from the server instead of one only.
serverMessage
=
br
.
readLine
();
System
.
out
.
println
(
"=================================================="
);
System
.
out
.
println
(
"The message the server sent was: '"
+
serverMessage
+
"'"
);
System
.
out
.
println
(
"FisherClient responds with: To get to the other side"
);
System
.
out
.
println
(
"Loop count: "
+
clientLoopCount
);
clientLoopCount
++;
// socket gets closed, either automatically/silently by this code (or possibly by the server)
}
// end while(true)
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Problem with FisherClient networking:"
);
// describe what is happening
System
.
err
.
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
)
{
System
.
err
.
println
(
"*** Be sure to stop any other running instances of programs using this port!"
);
}
}
finally
// occurs after any other activity when shutting down
{
// program exit: tell somebody about that happening. Likely cause: server drops connection.
System
.
out
.
println
();
System
.
out
.
println
(
"FisherClient exit"
);
}
}
}
package
MV3500Cohort2021JulySeptember.homework2.Fisher
;
//import static MV3500Cohort2020JulySeptember.homework2.White.WhiteClient.LOCALHOST;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
import
java.net.Socket
;
/**
* Before, we always used telnet (netcat) 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. The output at the server will
* show different socket pairs for each time the loop iterates.
*
* @author adfis
*/
public
class
FisherClient
{
// IPv6 String constant for localhost address, similarly IPv4 127.0.0.1
public
final
static
String
LOCALHOST
=
"172.20.145.10"
;
//"0:0:0:0:0:0:0:1";
// Sub with someone's IP
// Got it to work with McNeely in class
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public
static
void
main
(
String
[]
args
)
{
// Local variables/fields
Socket
socket
;
InputStream
is
;
InputStreamReader
isr
;
BufferedReader
br
;
OutputStream
os
;
PrintStream
ps
;
String
serverMessage
;
int
clientLoopCount
=
1
;
try
{
System
.
out
.
println
(
"FisherClient creating socket..."
);
// Made a loop counter for client to stop after 10 pings with server
while
(
clientLoopCount
<=
10
)
{
// 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 a Socket
// object; the server uses a ServerSocket to wait for
// connections.
socket
=
new
Socket
(
LOCALHOST
,
2317
);
os
=
socket
.
getOutputStream
();
ps
=
new
PrintStream
(
os
);
// Now hook everything up (i.e. set up the streams), Java style:
is
=
socket
.
getInputStream
();
isr
=
new
InputStreamReader
(
is
);
br
=
new
BufferedReader
(
isr
);
// Read a single line written by the server. We'd
// do things a bit differently if there were many lines to be read
// from the server instead of one only.
serverMessage
=
br
.
readLine
();
System
.
out
.
println
(
"=================================================="
);
System
.
out
.
println
(
"The message the server sent was: '"
+
serverMessage
+
"'"
);
System
.
out
.
println
(
"FisherClient responds with: To get to the other side"
);
System
.
out
.
println
(
"Loop count: "
+
clientLoopCount
);
clientLoopCount
++;
// socket gets closed, either automatically/silently by this code (or possibly by the server)
}
// end while(true)
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Problem with FisherClient networking:"
);
// describe what is happening
System
.
err
.
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
)
{
System
.
err
.
println
(
"*** Be sure to stop any other running instances of programs using this port!"
);
}
}
finally
// occurs after any other activity when shutting down
{
// program exit: tell somebody about that happening. Likely cause: server drops connection.
System
.
out
.
println
();
System
.
out
.
println
(
"FisherClient 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