Skip to content

Instantly share code, notes, and snippets.

@mickeypash
Created April 26, 2015 13:03
Show Gist options
  • Save mickeypash/b73c840a64958133dcf4 to your computer and use it in GitHub Desktop.
Save mickeypash/b73c840a64958133dcf4 to your computer and use it in GitHub Desktop.
Client-Server AP 2015 Simon's example
public class Server {
private static int PORT = 9000;
public static void main(String[] args){
ServerSocket listener = new ServerSocket(PORT);
Socket client = listener.accept();
PrintWriter out = new PrintWriter(client.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStream(client.getInputStream()));
while(true) {
String response
}
}
}
public class Client {
private static String SERVER = "localhost";
private static int PORT = 9000;
public static void main(String[] args) {
try {
Socket server = new Socket(SERVER,PORT);
PrintWriter out = new PrintWriter(server.getOutputStream(),true);
BufferedReader in = new BufferedReader(new InputStream(server.getInputStream()));
server.close();
} catch IOException() {
} finally {
server.close;
out.close;
in.close;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment