Initial commit

This commit is contained in:
2019-03-17 23:28:35 +08:00
commit 78b57e0eb3
10 changed files with 188 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,24 @@
import java.net.*;
import java.io.*;
public class SocketClient {
public static void main(String[] args) {
try {
// make connection to server socket
Socket sock = new Socket("127.0.0.1", 6017);
InputStream in = sock.getInputStream();
BufferedReader bin = new BufferedReader(new InputStreamReader(in));
// get a qoute from the socket
String line;
while ( (line = bin.readLine()) != null)
System.out.println(line);
// close the socket connection
sock.close();
}
catch (IOException ioe) {
System.err.println(ioe);
}
}
}

Binary file not shown.

View 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);
}
}
}