Initial commit
This commit is contained in:
36
Problem 3.16/SocketServer.java
Normal file
36
Problem 3.16/SocketServer.java
Normal file
@ -0,0 +1,36 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user