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 pathdcserver2.java
More file actions
Latest commit
35 lines (35 loc) · 1.06 KB
/
Copy pathdcserver2.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.*;
publicclassdcserver2
{
publicstaticvoidmain(String[] args) throwsException
{
//create server socket
ServerSocketsersock2 = newServerSocket(5000);
System.out.println("DeCentralized Server ready for communication");
//Make the server wait till a client accepts connection
Socketsock2 = sersock2.accept( );
//Sending to client
BufferedReaderkeyRead2 = newBufferedReader(newInputStreamReader(System.in));
OutputStreamostream2 = sock2.getOutputStream();
//To accept contents from client
PrintWriterpwrite2 = newPrintWriter(ostream2, true);
InputStreamistream2 = sock2.getInputStream();
BufferedReaderreceiveRead2 = newBufferedReader(newInputStreamReader(istream2));
//Read contents from the client
StringreceiveMessage2, sendMessage2;
receiveMessage2 = receiveRead2.readLine();
pwrite2.println("Start Test \n 7+7=");
while(true)
{
if(receiveMessage2.equals("14"))
{
pwrite2.println("answer is correct");
}
else
{
pwrite2.println("answer is wrong");
} // end of if else loop
} // end of while loop
} // end of main
} // end of class