Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- public class networking {
- static PrintWriter out = null;
- static BufferedReader in = null;
- static Socket server = new Socket();
- public void connect(String host, int port) {
- try {
- server = new Socket(host, port);
- out = new PrintWriter(server.getOutputStream(), true);
- in = new BufferedReader(new InputStreamReader(server.getInputStream()));
- } catch (UnknownHostException e) {
- System.err.println("Don't know about host: " + host);
- System.exit(1);
- } catch (IOException e) {
- System.err.println("Couldn't get I/O for the connection to: " + host);
- System.err.println("Server might be down.");
- System.exit(1);
- }
- }
- public void disconnect() {
- System.out.println("Bye!");
- try {
- server.close();
- out.close();
- in.close();
- } catch (IOException e) {
- System.err.println("Derp.");
- System.exit(1);
- }
- }
- public void send(String str) {
- out.println(str);
- }
- public String read() {
- String a = null;
- try {
- a = in.readLine();
- } catch (IOException e) {
- a = "Nothing to see here.";
- }
- return a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement