-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
23 lines (17 loc) · 718 Bytes
/
Server.java
File metadata and controls
23 lines (17 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.io.*;
import java.net.*;
public class Server {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(5000); // port
System.out.println("Server is running...");
Socket socket = serverSocket.accept(); // waits for client
System.out.println("Client connected!");
DataInputStream in = new DataInputStream(socket.getInputStream());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
String message = in.readUTF();
System.out.println("Client says: " + message);
out.writeUTF("Hello from Server!");
socket.close();
serverSocket.close();
}
}