37 lines
1.2 KiB
Java
37 lines
1.2 KiB
Java
import java.net.*;
|
|
import java.io.*;
|
|
|
|
public class SocketServer {
|
|
public static String[] qoutes = {
|
|
"Don't cry because it's over, smile because it happened.",
|
|
"Be yourself; everyone else is already taken.",
|
|
"Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.",
|
|
"So many books, so little time.",
|
|
"Be who you are and say what you feel, because those who mind don't matter, and those who matter don't mind."
|
|
};
|
|
|
|
public static void main(String[] args) {
|
|
try {
|
|
int i = 0;
|
|
ServerSocket sock = new ServerSocket(6017);
|
|
|
|
// Listening for connections
|
|
while (true) {
|
|
Socket client = sock.accept();
|
|
PrintWriter pout = new PrintWriter(client.getOutputStream(), true);
|
|
|
|
// write a qoute to the socket
|
|
pout.println(qoutes[i]);
|
|
i = (i + 1) % qoutes.length;
|
|
|
|
// close the socket and resume
|
|
// listening for connections
|
|
client.close();
|
|
}
|
|
}
|
|
catch (IOException ioe) {
|
|
System.err.println(ioe);
|
|
}
|
|
}
|
|
}
|