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
4d16165d
Commit
4d16165d
authored
6 years ago
by
danielcain
Browse files
Options
Downloads
Patches
Plain Diff
assignment 1 initial. unable to compile/run
parent
ec17f8ef
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
projects/Assignments/2018JulySeptember/homework1/CainAssignment1.java
+68
-0
68 additions, 0 deletions
...ignments/2018JulySeptember/homework1/CainAssignment1.java
with
68 additions
and
0 deletions
projects/Assignments/2018JulySeptember/homework1/CainAssignment1.java
0 → 100644
+
68
−
0
View file @
4d16165d
package
CainAssignment1
;
import
java.io.*
;
import
java.net.*
;
/**
* changed telnet # from 2317 to 2318. This won't affect the protocol handshake
* as long as client inputs the correct telnet #.
*
* telnet localhost 2318
*
* ask for the ip address of the server
* <code>telnet ipOfServersLaptop 2318</code>
*/
public
class
CainAssignment1
{
public
static
void
main
(
String
[]
args
)
{
try
{
int
popularityCount
=
0
;
// state
ServerSocket
serverSocket
=
new
ServerSocket
(
2318
);
// server decides here what port to listen on.
// of interest: often client doesn't care what port it uses locally when connecting to that server port.
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while
(
true
)
{
Socket
clientConnection
=
serverSocket
.
accept
();
// blocks! then proceeds once a connection is "accept"ed
/**
* changed connectionCount to popularityCount
*/
popularityCount
++;
OutputStream
os
=
clientConnection
.
getOutputStream
();
PrintStream
ps
=
new
PrintStream
(
os
);
ps
.
println
(
"This client response was written by server CainAssignment1"
);
// to remote client
System
.
out
.
println
(
"This server response was written by server CainAssignment1"
);
// to server console
ps
.
println
(
"You were connection #"
+
popularityCount
+
", by my count"
);
// 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
();
int
localPort
=
clientConnection
.
getLocalPort
();
int
remotePort
=
clientConnection
.
getPort
();
// remember the prior question, why are 2 ports different?
// My socket pair connection looks like this, to localhost:
// 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 ))
System
.
out
.
println
(
"Socket pair: (( "
+
localAddress
.
toString
()
+
", "
+
localPort
+
" ), ( "
+
remoteAddress
.
toString
()
+
", "
+
remotePort
+
" ))"
);
System
.
out
.
println
(
"you'er server is blowing up! Now serving #"
+
popularityCount
);
// report progress
ps
.
flush
();
clientConnection
.
close
();
}
}
catch
(
Exception
e
)
{
/**
* added to the println for fun
*/
System
.
out
.
println
(
"you got all sorts of problems with your 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