Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ublic class Connection {
- Thread con;
- Thread send;
- private Socket socket = null;
- private String ip;
- private int port;
- public Connection(String ip, int port) {
- this.ip = ip;
- this.port = port;
- }
- public void connect() {
- if (con != null) {
- con.stop();
- }
- con = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- socket = new Socket(ip, port);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
- con.start();
- }
- public void send(final String text) {
- try {
- PrintWriter p = new PrintWriter(socket.getOutputStream());
- p.write(text);
- p.flush();
- p.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement