Using Java to Query a Server for the Time

前端 未结 3 961
长情又很酷
长情又很酷 2021-01-20 19:24

I want to ask a server, whose IP I know, to send the date and time to a client.

How can I implement this in Java?

3条回答
  •  无人及你
    2021-01-20 19:50

    Your question is not clear so I'll post a number of possible answers.

    If the server exists and have a protocol to answer your request

    • A1. Create a program ( probably using Sockets ) to query that server.

    If the server exists but doesn't have a protocol to answer your request and YOU own that server and already logs ...which IP has been known to respond the date and time

    • A2. Read those logs in the server ( probably using InputStreamReader ) Create the protocol answer the request ( Socket ) and then go to A1.

    If the server exists but doesn't have a protocol to answer your request and you own that server and doesn't logs ...which IP has been known to respond the date and time

    • A3. Forget it

    If The server exists but doesn't have a protocol to answer your request and you DON'T own that server.

    • A4. Go to A3

    If the server doesn't exists and you can create it.

    • A5 Create the server code and then go to A2

    If the server doesn't exist and you cannot create it

    • A6 Go to A3

    ... And so on.

提交回复
热议问题