Advertisement
Guest User

Comms

a guest
May 4th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public class Comms {
  2. private Socket socket;
  3. private InputStream in;
  4. private OutputStream out;
  5. private ObjectInputStream oIn;
  6. private ObjectOutputStream oOut;
  7.  
  8. public Comms(Socket socket) {
  9. this.socket = socket;
  10. }
  11.  
  12. public Socket getSocket() {
  13. return socket;
  14. }
  15.  
  16. public void setSocket(Socket socket) {
  17. this.socket = socket;
  18. }
  19.  
  20. public Object recieveMessage() throws IOException, ClassNotFoundException {
  21.  
  22. Object recieved;
  23.  
  24. in = socket.getInputStream();
  25. oIn = new ObjectInputStream(in);
  26.  
  27. while ((recieved = oIn.readObject()) != null) {
  28. return recieved;
  29. }
  30.  
  31. return null;
  32. }
  33.  
  34. public void sendMessage(Object input) throws IOException {
  35. out = socket.getOutputStream();
  36. oOut = new ObjectOutputStream(out);
  37.  
  38. oOut.writeObject(input);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement