Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdcserver1.java
More file actions
Latest commit
35 lines (35 loc) · 1.06 KB
/
Copy pathdcserver1.java
File metadata and controls
35 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
importjava.io.*;
importjava.net.*;
publicclassdcserver1
{
publicstaticvoidmain(String[] args) throwsException
{
//create server socket
ServerSocketsersock1 = newServerSocket(4000);
System.out.println("DeCentralized Server ready for communication");
//Make the server wait till a client accepts connection
Socketsock1 = sersock1.accept( );
//Sending to client
BufferedReaderkeyRead1 = newBufferedReader(newInputStreamReader(System.in));
OutputStreamostream1 = sock1.getOutputStream();
//To accept contents from client
PrintWriterpwrite1 = newPrintWriter(ostream1, true);
InputStreamistream1 = sock1.getInputStream();
BufferedReaderreceiveRead1 = newBufferedReader(newInputStreamReader(istream1));
//Read contents from the client
StringreceiveMessage1, sendMessage1;
receiveMessage1 = receiveRead1.readLine();
pwrite1.println("Start Test \n 6+6=");
while(true)
{
if(receiveMessage1.equals("12"))
{
pwrite1.println("answer is correct");
}
else
{
pwrite1.println("answer is wrong");
} // end of if else loop
} // end of while loop
} // end of main
} // end of class