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 pathcserver.java
More file actions
Latest commit
35 lines (35 loc) · 1.05 KB
/
Copy pathcserver.java
File metadata and controls
35 lines (35 loc) · 1.05 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.*;
publicclasscserver
{
publicstaticvoidmain(String[] args) throwsException
{
//create server socket
ServerSocketsersock = newServerSocket(2000);
System.out.println("Centralized Server ready for communication");
//Make the server wait till a client accepts connection
Socketsock = sersock.accept( );
//Sending to client
BufferedReaderkeyRead = newBufferedReader(newInputStreamReader(System.in));
OutputStreamostream = sock.getOutputStream();
//To accept contents from client
PrintWriterpwrite = newPrintWriter(ostream, true);
InputStreamistream = sock.getInputStream();
BufferedReaderreceiveRead = newBufferedReader(newInputStreamReader(istream));
//Read contents from the client
StringreceiveMessage, sendMessage;
receiveMessage = receiveRead.readLine();
pwrite.println("Start Mathematics Test \n 2+2=");
while(true)
{
if(receiveMessage.equals("4"))
{
pwrite.println("answer is correct");
}
else
{
pwrite.println("answer is wrong");
} // end of if else loop
} // end of while loop
} // end of main
} // end of class