Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.lmu.cs.networking;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.Date;
- /**
- * A TCP server that runs on port 9090. When a client connects, it
- * sends the client the current date and time, then closes the
- * connection with that client. Arguably just about the simplest
- * server you can write.
- */
- public class DataServer {
- /**
- * Runs the server.
- */
- public static void main(String[] args) throws IOException {
- ServerSocket listener = new ServerSocket(43954);
- try {
- while (true) {
- Socket socket = listener.accept();
- try {
- PrintWriter out =
- new PrintWriter(socket.getOutputStream(), true);
- out.println(new Date().toString());
- } finally {
- socket.close();
- }
- }
- }
- finally {
- listener.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement