-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleServer.java
More file actions
34 lines (25 loc) · 977 Bytes
/
SimpleServer.java
File metadata and controls
34 lines (25 loc) · 977 Bytes
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
import java.net.*;
import java.io.*;
//Name: Jakob Millen
//ID: 1507831
public class SimpleServer {
public static void main(String[] args){
try{
//Listen on port 51333 for incoming connections
ServerSocket ss = new ServerSocket(51333);
System.out.println("Listening on port " + ss.getLocalPort());
while(true){
Socket s = ss.accept();
String clientAddress = s.getInetAddress().getHostName();
PrintWriter write = new PrintWriter(s.getOutputStream(), true);
//Send greeting to the client
write.println("Hello, " + clientAddress + ".");
write.println("Your IP address is " + s.getInetAddress().getHostAddress());
//Close the socket
s.close();
}
} catch (IOException e){
e.printStackTrace();
}
}
}