Created
April 26, 2015 13:03
-
-
Save mickeypash/b73c840a64958133dcf4 to your computer and use it in GitHub Desktop.
Client-Server AP 2015 Simon's example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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