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 DateServer {
- /**
- * Runs the server.
- */
- public static void main(String[] args) throws IOException {
- ServerSocket listener = new ServerSocket(9090);
- try {
- while (true) {
- Socket socket = listener.accept();
- try {
- DataOutputStream data = new DataOutputStream(file);
- data.writeInt(0xAAAA); // магическое число что-бы отеделять пакеты
- String json = "{text: \"hello world\"}";
- data.writeUTF(json);
- data.close();
- } finally {
- socket.close();
- }
- }
- }
- finally {
- listener.close();
- }
- }
- }
Add Comment
Please, Sign In to add comment