Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Socket Programmierung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dimitri Tayo Fongang Wembe
Socket Programmierung
Commits
bc593ef6
Commit
bc593ef6
authored
May 23, 2023
by
Dimitri Tayo Fongang Wembe
Browse files
Options
Downloads
Patches
Plain Diff
Update implementation of Server and client
parent
cdf7a2df
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
TCPClient.java
+35
-0
35 additions, 0 deletions
TCPClient.java
TCPServer.java
+39
-0
39 additions, 0 deletions
TCPServer.java
with
74 additions
and
0 deletions
TCPClient.java
+
35
−
0
View file @
bc593ef6
import
java.io.*
;
import
java.net.*
;
class
TCPClient
{
public
static
void
main
(
String
argv
[])
throws
Exception
{
InetAddress
localhost
=
InetAddress
.
getLocalHost
();
String
hostname
=
localhost
.
getHostName
();
//String sentence;
//String modifiedSentence;
/* BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in, "UTF-8")); */
Socket
clientSocket
=
new
Socket
(
hostname
,
2345
);
/* BufferedWriter outToServer = new BufferedWriter(
new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8")); */
DataOutputStream
dataOut
=
new
DataOutputStream
(
clientSocket
.
getOutputStream
());
/* BufferedReader inFromServer = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream(), "UTF-8")); */
//sentence = inFromUser.readLine();
//outToServer.write(sentence + '\n');
for
(
int
i
=
0
;
i
<=
1000000
;
i
++)
dataOut
.
writeInt
(
i
);
//outToServer.flush();
//modifiedSentence = inFromServer.readLine();
//System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket
.
close
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
TCPServer.java
+
39
−
0
View file @
bc593ef6
import
java.io.*
;
import
java.net.*
;
class
TCPServer
{
public
static
void
main
(
String
argv
[])
throws
Exception
{
//String clientSentence;
//String capitalizedSentence;
ServerSocket
welcomeSocket
=
new
ServerSocket
(
2345
);
int
input
;
while
(
true
)
{
Socket
connectSocket
=
welcomeSocket
.
accept
();
/* BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(connectSocket.getInputStream(),
"UTF-8")); */
DataInputStream
dataIn
=
new
DataInputStream
(
connectSocket
.
getInputStream
());
/* BufferedWriter outToClient = new BufferedWriter(
new OutputStreamWriter(connectSocket.getOutputStream(), "UTF-8")); */
//clientSentence = inFromClient.readLine();
for
(
int
i
=
0
;
i
<=
1000000
;
i
++)
{
input
=
dataIn
.
readInt
();
if
(
input
!=
i
)
{
System
.
out
.
println
(
"Error"
);
}
// Gilt nur zum Testen ob der Server tatsächlich die Zahlen erhält
// Also hier print nur die ersten 99 Zahlen :-)
if
(
i
<
100
)
System
.
out
.
println
(
input
);
}
//capitalizedSentence = clientSentence.toUpperCase() + '\n';
//outToClient.write(capitalizedSentence);
//outToClient.flush();
connectSocket
.
close
();
}
}
}
\ No newline at end of file
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