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
3e0a6765
Commit
3e0a6765
authored
4 years ago
by
stefa
Browse files
Options
Downloads
Patches
Plain Diff
Upload Homework 1 - Goericke
parent
ce140bc4
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/MV3500Cohort2020JulySeptember/homework1/GoerickeTcpExample1Telnet.java
+72
-0
72 additions, 0 deletions
...020JulySeptember/homework1/GoerickeTcpExample1Telnet.java
with
72 additions
and
0 deletions
assignments/src/MV3500Cohort2020JulySeptember/homework1/GoerickeTcpExample1Telnet.java
0 → 100644
+
72
−
0
View file @
3e0a6765
package
MV3500Cohort2020JulySeptember.homework1
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
/**
* Homework 1 for class MV3500 - Summer 2020
* @author Goericke, Stefan
*/
public
class
GoerickeTcpExample1Telnet
{
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
[]
args
)
throws
IOException
{
System
.
out
.
println
(
"Homework 1 MV3500 - Summer 2020 (Author: Stefan Goericke)"
);
System
.
out
.
println
(
"---------------------------------------------------------"
);
String
masterString
=
" ######### ###### # #\r\n"
;
masterString
=
masterString
+
" # # # #\r\n"
;
masterString
=
masterString
+
" # ###### # #\r\n"
;
masterString
=
masterString
+
" # # # #\r\n"
;
masterString
=
masterString
+
" # ###### #\r\n"
;
//build up connection
try
{
// build serverSOcket with port 2317
ServerSocket
serverSocket
=
new
ServerSocket
(
2317
);
System
.
out
.
println
(
"ServerSocket created with port 2317 ..."
);
// open client connection. Wait for answer (method accept)
System
.
out
.
println
(
"Open telnet client in cmd-console: telnet localhost 2317"
);
Socket
clientConnection
=
serverSocket
.
accept
();
System
.
out
.
println
(
"Client Connection established ..."
);
// create stream-objects
OutputStream
os
=
clientConnection
.
getOutputStream
();
PrintStream
ps
=
new
PrintStream
(
os
);
// already declared outside try-block
System
.
out
.
println
(
"Stream objects created ..."
);
try
{
// connection was established
System
.
out
.
println
(
"Connection established, sending message --> /n"
);
ps
.
println
(
"This client response was written by server TcpExample1."
);
ps
.
println
(
masterString
);
System
.
out
.
println
(
"This server response was written by server TcpExample1."
);
System
.
out
.
println
(
masterString
);
ps
.
flush
();
}
catch
(
Exception
e
){
// in case message could not be send
System
.
out
.
println
(
"Error while sending message .... press ENTER"
);
System
.
in
.
read
();
System
.
exit
(
0
);
}
clientConnection
.
close
();
}
catch
(
IOException
e
){
// connection could not be established
System
.
out
.
println
(
"Connection could not be established. Quit programm"
);
System
.
in
.
read
();
System
.
exit
(
0
);
}
}
}
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