Last active
August 29, 2015 14:11
A class to establish basic string based server / client talks
This file contains 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
class Connection{ | |
private static final String SERVER_ADDRESS = "<Use your ip adress here>"; | |
private static final int SERVER_PORT = <use your port here>; | |
private Socket socket = null; | |
private BufferedReader br = null; | |
private PrintStream ps = null; | |
public Connection(){ | |
try { | |
socket = new Socket(SERVER_ADDRESS, SERVER_PORT); | |
br = new BufferedReader(new InputStreamReader(socket.getInputStream())); | |
ps = new PrintStream(socket.getOutputStream()); | |
} catch (IOException e) { | |
Log.e("An error occurred: ", e.toString()); | |
} | |
} | |
public void transmit(String s){ | |
ps.println(s); | |
} | |
public String receive() throws IOException { | |
return br.readLine(); | |
} | |
public void stop() throws IOException { | |
ps.close(); | |
br.close(); | |
socket.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment