-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.java
37 lines (29 loc) · 1.18 KB
/
Server.java
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
36
37
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(6000);
System.out.println("Server started...");
while (true) {
Socket socket = serverSocket.accept();
System.out.println("Client connected...");
ObjectInputStream oIs = new ObjectInputStream(socket.getInputStream());
ObjectOutputStream oUs = new ObjectOutputStream(socket.getOutputStream());
try {
//read from client...
Object cMsg = oIs.readObject();
System.out.println("From Client : " + (String) cMsg);
String serverMsg = (String) cMsg;
serverMsg = serverMsg.toUpperCase();
//write to the client...
oUs.writeObject(serverMsg);
System.out.println("Message delivered successfully");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
}