-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
34 lines (33 loc) · 1.27 KB
/
Copy pathServer.java
File metadata and controls
34 lines (33 loc) · 1.27 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
package SocketProgramming;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.ServerSocket;
import java.rmi.ServerException;
import java.util.Scanner;
public class Server {
public static void main(String[] args) throws IOException {
ServerSocket soc = new ServerSocket(9998);
System.out.printf("Waiting for connection on port %d.......\n", soc.getLocalPort());
Socket sc = soc.accept();
Scanner s = new Scanner(System.in);
System.out.println("Connected with client address =" + sc.getInetAddress().toString() + " port associated with client =" + sc.getPort());
System.out.println("Type done to end");
while(true) {
System.out.println("Server :");
DataOutputStream ot = new DataOutputStream(sc.getOutputStream());
String msg = s.next();
ot.writeUTF(msg);
System.out.println("Client :");
DataInputStream in = new DataInputStream(sc.getInputStream());
String clientmsg = in.readUTF();
System.out.println(clientmsg);
if ("done".equalsIgnoreCase(clientmsg)) {
break;
}
}
soc.close();
sc.close();
}
}