-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkServer.java
More file actions
30 lines (29 loc) · 923 Bytes
/
NetworkServer.java
File metadata and controls
30 lines (29 loc) · 923 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
import java.util.*;
import java.net.*;
import java.io.*;
public class NetworkServer
{
public static void main(String[] args) throws Exception
{
System.out.println("Opening Socket");
ServerSocket server = new ServerSocket(17395);
System.out.println("Opened");
while(true)
{
try{
Socket client = server.accept();
System.out.println("Client Accepted");
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(client.getOutputStream()));
DataInputStream in = new DataInputStream(new BufferedInputStream(client.getInputStream()));
String str = in.readUTF();
System.out.printf("%s said %s",client.getRemoteSocketAddress(),str);
out.writeUTF("Hello, thank you for trying out networking! the flag is: [redacted]");
out.flush();
out.close();
in.close();
client.close();
System.out.println("Client Disconnected");
}catch(Exception e){e.printStackTrace();}
}
}
}