Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
setup_test_DPS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Michele Fiori
setup_test_DPS
Commits
107cc348
Commit
107cc348
authored
Feb 26, 2024
by
Michele Fiori
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switched comments to english
parent
c7cad982
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
15 deletions
+15
-15
TCPClient.java
src/main/java/TCPClient.java
+7
-7
TCPServer.java
src/main/java/TCPServer.java
+8
-8
No files found.
src/main/java/TCPClient.java
View file @
107cc348
...
@@ -6,29 +6,29 @@ class TCPClient {
...
@@ -6,29 +6,29 @@ class TCPClient {
String
sentence
;
String
sentence
;
String
modifiedSentence
;
String
modifiedSentence
;
/* Ini
zializza l'input stream (da tastiera)
*/
/* Ini
tialize input stream
*/
BufferedReader
inFromUser
=
BufferedReader
inFromUser
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
/* Ini
zializza una socket client, connessa al
server */
/* Ini
tialize a client socket, connected to the
server */
Socket
clientSocket
=
new
Socket
(
"localhost"
,
6789
);
Socket
clientSocket
=
new
Socket
(
"localhost"
,
6789
);
/* Ini
zializza lo stream di output verso la
socket */
/* Ini
tialize output stream towards the
socket */
DataOutputStream
outToServer
=
DataOutputStream
outToServer
=
new
DataOutputStream
(
clientSocket
.
getOutputStream
());
new
DataOutputStream
(
clientSocket
.
getOutputStream
());
/* Ini
zializza lo stream di input dalla
socket */
/* Ini
tialize input stream from the
socket */
BufferedReader
inFromServer
=
BufferedReader
inFromServer
=
new
BufferedReader
(
new
new
BufferedReader
(
new
InputStreamReader
(
clientSocket
.
getInputStream
()));
InputStreamReader
(
clientSocket
.
getInputStream
()));
/*
Legge una linea da tastiera
*/
/*
Read an input line
*/
sentence
=
inFromUser
.
readLine
();
sentence
=
inFromUser
.
readLine
();
/*
Invia la linea al server
*/
/*
Send the line to the server
*/
outToServer
.
writeBytes
(
sentence
+
'\n'
);
outToServer
.
writeBytes
(
sentence
+
'\n'
);
/*
Legge la risposta inviata dal server (linea terminata da \n
) */
/*
Read response from the server (string ending with '\n'
) */
modifiedSentence
=
inFromServer
.
readLine
();
modifiedSentence
=
inFromServer
.
readLine
();
System
.
out
.
println
(
"FROM SERVER: "
+
modifiedSentence
);
System
.
out
.
println
(
"FROM SERVER: "
+
modifiedSentence
);
...
...
src/main/java/TCPServer.java
View file @
107cc348
...
@@ -8,32 +8,32 @@ class TCPServer {
...
@@ -8,32 +8,32 @@ class TCPServer {
String
clientSentence
;
String
clientSentence
;
String
capitalizedSentence
;
String
capitalizedSentence
;
/* Crea
una "listening socket" sulla porta specificata
*/
/* Crea
te a "listening socket" on the specified port
*/
ServerSocket
welcomeSocket
=
new
ServerSocket
(
6789
);
ServerSocket
welcomeSocket
=
new
ServerSocket
(
6789
);
while
(
true
)
{
while
(
true
)
{
/*
/*
* Viene chiamata accept (bloccante).
* Call to accept function (blocking call).
* All'arrivo di una nuova connessione crea una nuova
* When a new connection arrives a new "established socket" is created
* "established socket"
*/
*/
Socket
connectionSocket
=
welcomeSocket
.
accept
();
Socket
connectionSocket
=
welcomeSocket
.
accept
();
/* Ini
zializza lo stream di input dalla
socket */
/* Ini
tialize input stream from the
socket */
BufferedReader
inFromClient
=
BufferedReader
inFromClient
=
new
BufferedReader
(
new
new
BufferedReader
(
new
InputStreamReader
(
connectionSocket
.
getInputStream
()));
InputStreamReader
(
connectionSocket
.
getInputStream
()));
/* Ini
zializza lo stream di output verso la
socket */
/* Ini
tialize output stream towards the
socket */
DataOutputStream
outToClient
=
DataOutputStream
outToClient
=
new
DataOutputStream
(
connectionSocket
.
getOutputStream
());
new
DataOutputStream
(
connectionSocket
.
getOutputStream
());
/*
Legge una linea (terminata da \n) dal
client */
/*
Read a line (ending with '\n') from the
client */
clientSentence
=
inFromClient
.
readLine
();
clientSentence
=
inFromClient
.
readLine
();
/* Build the response */
capitalizedSentence
=
clientSentence
.
toUpperCase
()
+
'\n'
;
capitalizedSentence
=
clientSentence
.
toUpperCase
()
+
'\n'
;
/*
Invia la risposta al
client */
/*
Send the response to the
client */
outToClient
.
writeBytes
(
capitalizedSentence
);
outToClient
.
writeBytes
(
capitalizedSentence
);
connectionSocket
.
close
();
connectionSocket
.
close
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment