-1

The problem is I only found a little description about port 17, also known as "Quote of the date" port. Useless port, does nothing but display a quote which is less than 512 ASCII characters. Could someone give me more information about how to listen to port 17 in Java? I have established a server client socket using port:6017.

Here is the code:

public class DateServer {
    public static void main(String[] args) {
        try {
            ServerSocket sock = new ServerSocket(6017);

            // now listen for connections
            while (true) {
                Socket client = sock.accept();
                // we have a connection

                PrintWriter pout = new PrintWriter(client.getOutputStream(), true);
                // write the Date to the socket
                pout.println(); // I know something must happens here!!!

                // close the socket and resume listening for more connections
                client.close();
            }
        } catch (IOException ioe) {
            System.err.println(ioe);
        }
    }
}

The system runs in Linux and this code is the server end of the program. I am working on the Client part, and try to make the server do the same thing like port 17 then have a client to receive the "quote of the day" from the server.

John
  • 59
  • 1
  • 2
  • 13
  • 1
    Run your server program on port 17, only if it(your system) allows. There's going to be an administrative intervention as first 1023 ports are reserved in TCP connection, unless you adjust the things. – Am_I_Helpful Oct 10 '15 at 05:21
  • 1
    What kind of system are you running it on? – Elliott Frisch Oct 10 '15 at 05:22
  • If you are running Linux (see Elliot's question to you), then this post describes what you need to do (and your question would be a duplicate of it) : http://stackoverflow.com/questions/413807/is-there-a-way-for-non-root-processes-to-bind-to-privileged-ports-1024-on-l – Erwin Bolwidt Oct 10 '15 at 05:30
  • I'm run on linux system. – John Oct 10 '15 at 05:38
  • 1
    Do you need to write a server? or a client? i.e. are you wanting to *send* quotd, or *receive* it? – user207421 Oct 10 '15 at 05:39
  • Thank you guys, problem just got solved. I need to write a server that like port 17 to send a quote of date to the server I write. – John Oct 10 '15 at 05:46
  • @John No you don't. A server can't send to a server. You need to clarify your requirement. – user207421 Oct 10 '15 at 05:47
  • Sorry for the confusion, I was meant client. – John Oct 10 '15 at 06:04

1 Answers1

3

Ports less than 1024 are privileged and require escalated permissions to run. Run your program as an administrator of your machine with the port set to 17.

Makoto
  • 104,088
  • 27
  • 192
  • 230